From 94619e3fe44821c04e837f6b15e959a7992b6b07 Mon Sep 17 00:00:00 2001 From: SpectralEdge Date: Fri, 2 Mar 2012 22:19:30 -0800 Subject: [PATCH] Added default radius setting for butcher and added permissions for killing pets, npcs, and non hostile animals. --- .../sk89q/worldedit/LocalConfiguration.java | 1 + .../worldedit/commands/UtilityCommands.java | 30 +++++++++++++++---- .../util/PropertiesConfiguration.java | 1 + .../worldedit/util/YAMLConfiguration.java | 1 + src/main/resources/config.yml | 3 ++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 8dd24cc8a..b1cac8eb8 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -101,6 +101,7 @@ public abstract class LocalConfiguration { public String saveDir = "schematics"; public String scriptsDir = "craftscripts"; public boolean showFirstUseVersion = true; + public int butcherDefaultRadius = -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 1155ad45c..0921077fb 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -349,7 +349,7 @@ public class UtilityCommands { flags = "plan", desc = "Kill all or nearby mobs", help = - "Kills nearby mobs, or all mobs if you don't specify a radius.\n" + + "Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" + "Flags:" + " -p also kills pets.\n" + " -n also kills NPCs.\n" + @@ -364,12 +364,30 @@ public class UtilityCommands { public void butcher(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int radius = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : -1; - + LocalConfiguration config = we.getConfiguration(); + + final int radius; + + if(args.argsLength() > 0){ + radius = Math.max(1, args.getInteger(0)); + } + else{ + radius = config.butcherDefaultRadius; + } + int flags = 0; - if (args.hasFlag('p')) flags |= KillFlags.PETS; - if (args.hasFlag('n')) flags |= KillFlags.NPCS; - if (args.hasFlag('a')) flags |= KillFlags.ANIMALS; + if (player.hasPermission("worldedit.butcher.pets") && (args.hasFlag('p'))) { + flags |= KillFlags.PETS; + } + + if (player.hasPermission("worldedit.butcher.npcs") && (args.hasFlag('n'))) { + flags |= KillFlags.NPCS; + } + + if (player.hasPermission("worldedit.butcher.animals") && (args.hasFlag('a'))) { + flags |= KillFlags.ANIMALS; + } + if (args.hasFlag('l') && player.hasPermission("worldedit.butcher.lightning")) flags |= KillFlags.WITH_LIGHTNING; int killed; diff --git a/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index 9fbb11a42..50a173868 100644 --- a/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -95,6 +95,7 @@ public class PropertiesConfiguration extends LocalConfiguration { navigationWand = getInt("nav-wand-item", navigationWand); navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance); scriptTimeout = getInt("scripting-timeout", scriptTimeout); + butcherDefaultRadius = getInt("butcher-default-radius", butcherDefaultRadius); LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15)); diff --git a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 53975739a..08fe0ef67 100644 --- a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -83,6 +83,7 @@ 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 70cdd5a50..42c6f11f2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -54,6 +54,9 @@ history: size: 15 expiration: 10 +butcher: + butcher-default-radius: -1 + wand-item: 271 shell-save-type: no-double-slash: false