From 8868aa94d3f04b1ef8ce765535c3422a89a02684 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 23 Mar 2014 19:40:03 +0100 Subject: [PATCH] The /butcher command no longer kills mobs with a name tag. This behaviour can be overridden with the new -t flag. The -f flag encompasses this flag. --- src/main/java/com/sk89q/worldedit/LocalWorld.java | 3 ++- .../java/com/sk89q/worldedit/bukkit/BukkitWorld.java | 9 +++++++++ .../java/com/sk89q/worldedit/commands/BrushCommands.java | 1 + .../com/sk89q/worldedit/commands/UtilityCommands.java | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index 449faa681..939286e9c 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -53,7 +53,8 @@ public abstract class LocalWorld implements World { public static final int ANIMALS = 1 << 2; public static final int GOLEMS = 1 << 3; public static final int AMBIENT = 1 << 4; - public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT; + public static final int TAGGED = 1 << 5; + public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT | TAGGED; public static final int WITH_LIGHTNING = 1 << 20; } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index c7bf76097..9046a5759 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -936,6 +936,7 @@ public class BukkitWorld extends LocalWorld { boolean withLightning = (flags & KillFlags.WITH_LIGHTNING) != 0; boolean killGolems = (flags & KillFlags.GOLEMS) != 0; boolean killAmbient = (flags & KillFlags.AMBIENT) != 0; + boolean killTagged = (flags & KillFlags.TAGGED) != 0; int num = 0; double radiusSq = radius * radius; @@ -967,6 +968,10 @@ public class BukkitWorld extends LocalWorld { continue; } + if (!killTagged && isTagged(ent)) { + continue; + } + if (radius < 0 || bukkitOrigin.distanceSquared(ent.getLocation()) <= radiusSq) { if (withLightning) { world.strikeLightningEffect(ent.getLocation()); @@ -979,6 +984,10 @@ public class BukkitWorld extends LocalWorld { return num; } + private static boolean isTagged(LivingEntity ent) { + return ent.getCustomName() != null; + } + /** * Remove entities in an area. * diff --git a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java index cffe67220..e49e0fd39 100644 --- a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java @@ -281,6 +281,7 @@ public class BrushCommands { flags.or(KillFlags.GOLEMS , flagString.contains("g"), "worldedit.butcher.golems"); flags.or(KillFlags.ANIMALS , flagString.contains("a"), "worldedit.butcher.animals"); flags.or(KillFlags.AMBIENT , flagString.contains("b"), "worldedit.butcher.ambient"); + flags.or(KillFlags.TAGGED , flagString.contains("t"), "worldedit.butcher.tagged"); flags.or(KillFlags.WITH_LIGHTNING, flagString.contains("l"), "worldedit.butcher.lightning"); } BrushTool tool = session.getBrushTool(player.getItemInHand()); diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 12b88fbf6..162014788 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -345,7 +345,7 @@ public class UtilityCommands { @Command( aliases = { "butcher" }, usage = "[radius]", - flags = "plangbf", + flags = "plangbtf", 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 { " -g also kills Golems.\n" + " -a also kills animals.\n" + " -b also kills ambient mobs.\n" + + " -t also kills mobs with name tags.\n" + " -f compounds all previous flags.\n" + " -l strikes lightning on each killed mob.", min = 0, @@ -390,6 +391,7 @@ public class UtilityCommands { flags.or(KillFlags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems"); flags.or(KillFlags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals"); flags.or(KillFlags.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient"); + flags.or(KillFlags.TAGGED , args.hasFlag('t'), "worldedit.butcher.tagged"); flags.or(KillFlags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); // If you add flags here, please add them to com.sk89q.worldedit.commands.BrushCommands.butcherBrush() as well