From 6c189c4ff910d3f6fe2ae3c6fd8155444ddb7448 Mon Sep 17 00:00:00 2001 From: Wizjany Date: Tue, 25 Dec 2012 18:34:17 -0500 Subject: [PATCH] Added butcher flag for ambient mobs. --- .../java/com/sk89q/worldedit/LocalWorld.java | 3 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 28 ++++++++++--------- .../worldedit/commands/UtilityCommands.java | 4 ++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index 618395ca0..226256f06 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -51,7 +51,8 @@ public abstract class LocalWorld implements World { 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 AMBIENT = 1 << 4; + public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT; 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 0d15ad89d..28a605d9f 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -43,11 +43,13 @@ import org.bukkit.block.CreatureSpawner; import org.bukkit.block.Furnace; import org.bukkit.block.Sign; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Ambient; import org.bukkit.entity.Animals; import org.bukkit.entity.Boat; import org.bukkit.entity.Entity; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Golem; import org.bukkit.entity.Hanging; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Item; @@ -58,6 +60,7 @@ import org.bukkit.entity.Painting; import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; +import org.bukkit.entity.Villager; import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -618,6 +621,7 @@ public class BukkitWorld extends LocalWorld { boolean killAnimals = (flags & KillFlags.ANIMALS) != 0; boolean withLightning = (flags & KillFlags.WITH_LIGHTNING) != 0; boolean killGolems = (flags & KillFlags.GOLEMS) != 0; + boolean killAmbient = (flags & KillFlags.AMBIENT) != 0; int num = 0; double radiusSq = radius * radius; @@ -634,22 +638,20 @@ public class BukkitWorld extends LocalWorld { } if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) { - continue; // tamed wolf + continue; // tamed pet } - try { - // Temporary solution to fix Golems being butchered. - if (!killGolems && Class.forName("org.bukkit.entity.Golem").isAssignableFrom(ent.getClass())) { - continue; - } - } catch (ClassNotFoundException e) {} + if (!killGolems && ent instanceof Golem) { + continue; + } - try { - // Temporary solution until org.bukkit.entity.NPC is widely deployed. - if (!killNPCs && Class.forName("org.bukkit.entity.NPC").isAssignableFrom(ent.getClass())) { - continue; - } - } catch (ClassNotFoundException e) {} + if (!killNPCs && ent instanceof Villager) { + continue; + } + + if (!killAmbient && ent instanceof Ambient) { + continue; + } if (radius < 0 || bukkitOrigin.distanceSquared(ent.getLocation()) <= radiusSq) { if (withLightning) { diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 8959eaac7..5714bd1de 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -356,7 +356,7 @@ public class UtilityCommands { @Command( aliases = { "butcher" }, usage = "[radius]", - flags = "plangf", + flags = "plangbf", desc = "Kill all or nearby mobs", help = "Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" + @@ -365,6 +365,7 @@ public class UtilityCommands { " -n also kills NPCs.\n" + " -g also kills Golems.\n" + " -a also kills animals.\n" + + " -b also kills ambient mobs.\n" + " -f compounds all previous flags.\n" + " -l strikes lightning on each killed mob.", min = 0, @@ -399,6 +400,7 @@ public class UtilityCommands { 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.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient"); flags.or(KillFlags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); int killed;