Added butcher flag for ambient mobs.

This commit is contained in:
Wizjany 2012-12-25 18:34:17 -05:00
parent e728445383
commit 6c189c4ff9
3 changed files with 20 additions and 15 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;