From 56d534bf0dce89d0ad692b954249a7dfdacc9d5d Mon Sep 17 00:00:00 2001 From: Wizjany Date: Fri, 23 Nov 2012 20:10:38 -0500 Subject: [PATCH] Use right config value for butcher radius. Add max radius for butcher. --- .../com/sk89q/worldedit/LocalConfiguration.java | 8 +++++--- .../sk89q/worldedit/commands/UtilityCommands.java | 15 ++++++++++----- .../sk89q/worldedit/util/YAMLConfiguration.java | 15 ++++++++------- src/main/resources/config.yml | 8 ++++---- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 766949721..487db6728 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -19,13 +19,14 @@ package com.sk89q.worldedit; -import com.sk89q.worldedit.blocks.BlockID; -import com.sk89q.worldedit.blocks.ItemID; -import com.sk89q.worldedit.snapshots.SnapshotRepository; import java.io.File; import java.util.HashSet; import java.util.Set; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.blocks.ItemID; +import com.sk89q.worldedit.snapshots.SnapshotRepository; + /** * Represents WorldEdit's configuration. * @@ -104,6 +105,7 @@ public abstract class LocalConfiguration { public String scriptsDir = "craftscripts"; public boolean showFirstUseVersion = true; public int butcherDefaultRadius = -1; + public int butcherMaxRadius = -1; /** * Loads the configuration. diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 22b755b42..c8b3e0a07 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -378,13 +378,18 @@ public class UtilityCommands { LocalConfiguration config = we.getConfiguration(); + // technically the default can be larger than the max, but that's not my problem int radius = config.butcherDefaultRadius; - if (args.argsLength() > 0) { - if (args.getString(0).equals("all")) { - radius = -1; - } else { - radius = Math.max(1, args.getInteger(0)); + // there might be a better way to do this but my brain is fried right now + if (args.argsLength() > 0) { // user inputted radius, override the default + radius = args.getInteger(0); + if (config.butcherMaxRadius != -1) { // clamp if there is a max + if (radius == -1) { + radius = config.butcherMaxRadius; + } else { // Math.min does not work if radius is -1 (actually highest possible value) + radius = Math.min(radius, config.butcherMaxRadius); + } } } diff --git a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 71ac13307..1aa05f784 100644 --- a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -19,12 +19,6 @@ package com.sk89q.worldedit.util; -import com.sk89q.util.yaml.YAMLProcessor; -import com.sk89q.worldedit.LocalConfiguration; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.LogFormat; -import com.sk89q.worldedit.snapshots.SnapshotRepository; - import java.io.File; import java.io.IOException; import java.util.HashSet; @@ -33,6 +27,12 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; +import com.sk89q.util.yaml.YAMLProcessor; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.LogFormat; +import com.sk89q.worldedit.snapshots.SnapshotRepository; + /** * A less simple implementation of {@link LocalConfiguration} using YAML configuration files. * @@ -71,6 +71,8 @@ public class YAMLConfiguration extends LocalConfiguration { maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius)); maxSuperPickaxeSize = Math.max(1, config.getInt( "limits.max-super-pickaxe-size", maxSuperPickaxeSize)); + butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius)); + butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius)); registerHelp = true; logCommands = config.getBoolean("logging.log-commands", logCommands); superPickaxeDrop = config.getBoolean("super-pickaxe.drop-items", @@ -88,7 +90,6 @@ public class YAMLConfiguration extends LocalConfiguration { scriptTimeout = config.getInt("scripting.timeout", scriptTimeout); scriptsDir = config.getString("scripting.dir", scriptsDir); - butcherDefaultRadius = config.getInt("butcher-default-radius", butcherDefaultRadius); saveDir = config.getString("saving.dir", saveDir); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 63bb26063..05227d5ff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -25,6 +25,9 @@ limits: max-radius: -1 max-super-pickaxe-size: 5 max-brush-radius: 5 + butcher-radius: + default: -1 + maximum: -1 disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83] use-inventory: @@ -56,10 +59,7 @@ saving: history: size: 15 expiration: 10 - -butcher: - butcher-default-radius: -1 - + wand-item: 271 shell-save-type: no-double-slash: false