The /butcher command no longer kills NPCs, except when the -n flag is passed.

Also:
- Moved some code from BukkitWorld to LocalWorld.
- Replaced the "boolean killPets" argument by an "int flags" to provide extensibility
- Made the radius argument a double
- Basically rewrote the entire function
- Deprecated all old versions of killMobs
This commit is contained in:
TomyLobo
2011-12-06 06:26:12 +01:00
parent 4c9e0a629f
commit bc3a4377ec
3 changed files with 64 additions and 28 deletions

View File

@ -488,41 +488,43 @@ public class BukkitWorld extends LocalWorld {
}
/**
* Kill mobs in an area, excluding tamed wolves.
*
* @param origin
* @param radius -1 for all mobs
* @return
*/
@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
* @param origin The center of the area to kill mobs in.
* @param radius Maximum distance to kill mobs at; radius < 0 means kill all mobs
* @param flags various flags that determine what to kill
* @return
*/
@Override
public int killMobs(Vector origin, int radius, boolean killPets) {
public int killMobs(Vector origin, double radius, int flags) {
boolean killPets = (flags & KillFlags.PETS) != 0;
boolean killNPCs = (flags & KillFlags.NPCS) != 0;
int num = 0;
double radiusSq = Math.pow(radius, 2);
double radiusSq = radius * radius;
Location bukkitOrigin = BukkitUtil.toLocation(world, origin);
for (LivingEntity ent : world.getLivingEntities()) {
if (ent instanceof HumanEntity) {
continue;
}
if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) {
continue; // tamed wolf
}
if (ent instanceof LivingEntity && !(ent instanceof HumanEntity)) {
if (radius == -1
|| origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) <= radiusSq) {
ent.remove();
++num;
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 (radius < 0 || bukkitOrigin.distanceSquared(ent.getLocation()) <= radiusSq) {
ent.remove();
++num;
}
}