From 8f032fb2ea3d986b1d7e2d083fcd4b36307ccfa0 Mon Sep 17 00:00:00 2001 From: Wizjany Date: Tue, 24 May 2011 18:19:11 -0400 Subject: [PATCH] Added -p flag to //butcher to kill pet wolves. --- .../java/com/sk89q/worldedit/LocalWorld.java | 12 ++++++++++- .../sk89q/worldedit/bukkit/BukkitWorld.java | 21 ++++++++++++++++--- .../worldedit/commands/UtilityCommands.java | 3 ++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index 48725bd87..77a4a7043 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -256,7 +256,7 @@ public abstract class LocalWorld { } /** - * Kill mobs in an area. + * Kill mobs in an area, excluding pet wolves. * * @param origin * @param radius @@ -264,6 +264,16 @@ public abstract class LocalWorld { */ public abstract int killMobs(Vector origin, int radius); + /** + * Kill mobs in an area. + * + * @param origin + * @param radius + * @param killPets + * @return + */ + public abstract int killMobs(Vector origin, int radius, boolean killPets); + /** * Remove entities in an area. * diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 4dbc39be3..1c3700513 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -391,7 +391,7 @@ public class BukkitWorld extends LocalWorld { } /** - * Kill mobs in an area. + * Kill mobs in an area, excluding tamed wolves. * * @param origin * @param radius -1 for all mobs @@ -399,12 +399,27 @@ public class BukkitWorld extends LocalWorld { */ @Override public int killMobs(Vector origin, int radius) { + return killMobs(origin, radius, false); + } + + /** + * Kill mobs in an area. + * + * @param origin + * @param radius -1 for all mobs + * @param killPets true to kill tames wolves + * @return + */ + @Override + public int killMobs(Vector origin, int radius, boolean killPets) { int num = 0; double radiusSq = Math.pow(radius, 2); for (LivingEntity ent : world.getLivingEntities()) { - if ((ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) - && !(ent instanceof Wolf)) { + if (!killPets && ent instanceof Wolf && ((Wolf) ent).isTamed()) { + continue; // tamed wolf + } + if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) { if (radius == -1 || origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) <= radiusSq) { ent.remove(); diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 1edb512be..6d9ce9f43 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -307,6 +307,7 @@ public class UtilityCommands { @Command( aliases = {"butcher"}, usage = "[radius]", + flags = "p", desc = "Kill all or nearby mobs", min = 0, max = 1 @@ -320,7 +321,7 @@ public class UtilityCommands { Math.max(1, args.getInteger(0)) : -1; Vector origin = session.getPlacementPosition(player); - int killed = player.getWorld().killMobs(origin, radius); + int killed = player.getWorld().killMobs(origin, radius, args.hasFlag('p')); player.print("Killed " + killed + " mobs."); }