From 499f3ccda7bb8b319fc322df659638d27bc8d23c Mon Sep 17 00:00:00 2001 From: aumgn Date: Sat, 17 Mar 2012 09:09:31 +0100 Subject: [PATCH] Add a -f (friendly) flag to butcher --- .../java/com/sk89q/worldedit/LocalWorld.java | 1 + .../worldedit/commands/UtilityCommands.java | 52 +++++++++++-------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index ca9d25b75..ba92de2e9 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -40,6 +40,7 @@ public abstract class LocalWorld { public static final int NPCS = 1 << 1; public static final int ANIMALS = 1 << 2; public static final int GOLEMS = 1 << 3; + public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS; public static final int WITH_LIGHTNING = 1 << 20; } diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index e065ae22a..4a8f9c245 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -346,7 +346,7 @@ public class UtilityCommands { @Command( aliases = { "butcher" }, usage = "[radius]", - flags = "plang", + flags = "plangf", desc = "Kill all or nearby mobs", help = "Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" + @@ -355,6 +355,7 @@ public class UtilityCommands { " -n also kills NPCs.\n" + " -g also kills Golems.\n" + " -a also kills animals.\n" + + " -f compounds all previous flags.\n" + " -l strikes lightning on each killed mob.", min = 0, max = 1 @@ -375,39 +376,48 @@ public class UtilityCommands { else{ radius = config.butcherDefaultRadius; } - - int flags = 0; - 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.golems") && (args.hasFlag('g'))) { - flags |= KillFlags.GOLEMS; - } - - 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; + FlagContainer flags = new FlagContainer(player); + flags.or(KillFlags.FRIENDLY , args.hasFlag('f')); + flags.or(KillFlags.PETS , args.hasFlag('p'), "worldedit.butcher.pets"); + flags.or(KillFlags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs"); + flags.or(KillFlags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems"); + flags.or(KillFlags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals"); + flags.or(KillFlags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); int killed; if (player.isPlayer()) { - killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags); + killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags); } else { killed = 0; for (LocalWorld world : we.getServer().getWorlds()) { - killed += world.killMobs(new Vector(), radius, flags); + killed += world.killMobs(new Vector(), radius, flags.flags); } } player.print("Killed " + killed + " mobs."); } + public class FlagContainer { + private final LocalPlayer player; + public int flags = 0; + public FlagContainer(LocalPlayer player) { + this.player = player; + } + + public void or(int flag, boolean on) { + if (on) flags |= flag; + } + + public void or(int flag, boolean on, String permission) { + or(flag, on); + + if ((flags & flag) != 0 && !player.hasPermission(permission)) { + flags &= ~flag; + } + } + } + @Command( aliases = { "remove", "rem", "rement" }, usage = " ",