From ec9c77c31bd06114197d13ce55452de11bddfbb1 Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 22 Jan 2015 15:48:45 -0500 Subject: [PATCH] Excluded armor stands from //butcher by default. Someone got lazy and just made armor stands a living entity instead of extracting an ArmorEquippable interface. --- .../com/sk89q/worldedit/bukkit/BukkitEntityType.java | 12 +++++++++--- .../com/sk89q/worldedit/command/BrushCommands.java | 12 ++++-------- .../com/sk89q/worldedit/command/UtilityCommands.java | 5 +++-- .../worldedit/command/util/CreatureButcher.java | 8 ++++++++ .../sk89q/worldedit/entity/metadata/EntityType.java | 6 ++++++ .../com/sk89q/worldedit/forge/ForgeEntityType.java | 5 +++++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java index d80526c83..57e57c29b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java @@ -38,13 +38,14 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.Villager; +import org.bukkit.entity.minecart.ExplosiveMinecart; import static com.google.common.base.Preconditions.checkNotNull; class BukkitEntityType implements EntityType { - private static final org.bukkit.entity.EntityType tntMinecartType = - Enums.findByValue(org.bukkit.entity.EntityType.class, "MINECART_TNT"); + private static final org.bukkit.entity.EntityType armorStandType = + Enums.findByValue(org.bukkit.entity.EntityType.class, "ARMOR_STAND"); private final Entity entity; @@ -95,7 +96,7 @@ class BukkitEntityType implements EntityType { @Override public boolean isTNT() { - return entity instanceof TNTPrimed || entity.getType() == tntMinecartType; + return entity instanceof TNTPrimed || entity instanceof ExplosiveMinecart; } @Override @@ -137,4 +138,9 @@ class BukkitEntityType implements EntityType { public boolean isTagged() { return entity instanceof LivingEntity && ((LivingEntity) entity).getCustomName() != null; } + + @Override + public boolean isArmorStand() { + return entity.getType() == armorStandType; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 1ce10523e..a6f2c2d24 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -22,12 +22,7 @@ package com.sk89q.worldedit.command; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalConfiguration; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.command.tool.BrushTool; @@ -229,10 +224,10 @@ public class BrushCommands { @Command( aliases = { "butcher", "kill" }, usage = "[radius]", - flags = "plangbtf", + flags = "plangbtfr", desc = "Butcher brush", help = "Kills nearby mobs within the specified radius.\n" + - "Flags:" + + "Flags:\n" + " -p also kills pets.\n" + " -n also kills NPCs.\n" + " -g also kills Golems.\n" + @@ -240,6 +235,7 @@ public class BrushCommands { " -b also kills ambient mobs.\n" + " -t also kills mobs with name tags.\n" + " -f compounds all previous flags.\n" + + " -r also destroys armor stands.\n" + " -l currently does nothing.", min = 0, max = 1 diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 0c72f4cba..86ee9d232 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -366,11 +366,11 @@ public class UtilityCommands { @Command( aliases = { "butcher" }, usage = "[radius]", - flags = "plangbtf", + flags = "plangbtfr", desc = "Kill all or nearby mobs", help = "Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" + - "Flags:" + + "Flags:\n" + " -p also kills pets.\n" + " -n also kills NPCs.\n" + " -g also kills Golems.\n" + @@ -378,6 +378,7 @@ public class UtilityCommands { " -b also kills ambient mobs.\n" + " -t also kills mobs with name tags.\n" + " -f compounds all previous flags.\n" + + " -r also destroys armor stands.\n" + " -l currently does nothing.", min = 0, max = 1 diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java index 822389bbe..7623d338e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java @@ -41,6 +41,7 @@ public class CreatureButcher { public static final int AMBIENT = 1 << 4; public static final int TAGGED = 1 << 5; public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT | TAGGED; + public static final int ARMOR_STAND = 1 << 6; public static final int WITH_LIGHTNING = 1 << 20; private Flags() { @@ -74,6 +75,8 @@ public class CreatureButcher { or(Flags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals"); or(Flags.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient"); or(Flags.TAGGED , args.hasFlag('t'), "worldedit.butcher.tagged"); + or(Flags.ARMOR_STAND , args.hasFlag('r'), "worldedit.butcher.armorstands"); + or(Flags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); } @@ -87,6 +90,7 @@ public class CreatureButcher { boolean killGolems = (flags & Flags.GOLEMS) != 0; boolean killAmbient = (flags & Flags.AMBIENT) != 0; boolean killTagged = (flags & Flags.TAGGED) != 0; + boolean killArmorStands = (flags & Flags.ARMOR_STAND) != 0; EntityType type = entity.getFacet(EntityType.class); @@ -126,6 +130,10 @@ public class CreatureButcher { return false; } + if (!killArmorStands && type.isArmorStand()) { + return false; + } + entity.remove(); return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java index a12225414..f13cfd808 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java @@ -148,4 +148,10 @@ public interface EntityType { */ boolean isTagged(); + /** + * Test whether the entity is an armor stand. + * + * @return true if an armor stand + */ + boolean isArmorStand(); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java index 9db2e7431..4888c748d 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java @@ -135,4 +135,9 @@ public class ForgeEntityType implements EntityType { public boolean isTagged() { return entity instanceof EntityLiving && ((EntityLiving) entity).hasCustomNameTag(); } + + @Override + public boolean isArmorStand() { + return false; // TODO re-add when forge version is updated to 1.8: entity instanceof EntityArmorStand; + } }