Added a -a flag to /butcher to kill animals. Its now disabled by default.

This commit is contained in:
TomyLobo 2011-12-06 07:08:32 +01:00
parent bc3a4377ec
commit c21c380bba
3 changed files with 12 additions and 3 deletions

View File

@ -38,6 +38,7 @@ public abstract class LocalWorld {
public class KillFlags {
public static final int PETS = 1 << 0;
public static final int NPCS = 1 << 1;
public static final int ANIMALS = 1 << 2;
}
/**

View File

@ -33,6 +33,7 @@ import org.bukkit.block.Furnace;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
@ -500,6 +501,7 @@ public class BukkitWorld extends LocalWorld {
public int killMobs(Vector origin, double radius, int flags) {
boolean killPets = (flags & KillFlags.PETS) != 0;
boolean killNPCs = (flags & KillFlags.NPCS) != 0;
boolean killAnimals = (flags & KillFlags.ANIMALS) != 0;
int num = 0;
double radiusSq = radius * radius;
@ -511,6 +513,10 @@ public class BukkitWorld extends LocalWorld {
continue;
}
if (!killAnimals && ent instanceof Animals) {
continue;
}
if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) {
continue; // tamed wolf
}

View File

@ -345,13 +345,14 @@ public class UtilityCommands {
@Command(
aliases = { "butcher" },
usage = "[radius]",
flags = "pn",
flags = "pna",
desc = "Kill all or nearby mobs",
help =
"Kills nearby mobs, or all mobs if you don't specify a radius.\n" +
"Flags:" +
" -p also kill pets.\n" +
" -n also kill NPCs.",
" -p also kills pets.\n" +
" -n also kills NPCs.\n" +
" -a also kills animals.",
min = 0,
max = 1
)
@ -368,6 +369,7 @@ public class UtilityCommands {
int flags = 0;
if (args.hasFlag('p')) flags |= KillFlags.PETS;
if (args.hasFlag('n')) flags |= KillFlags.NPCS;
if (args.hasFlag('a')) flags |= KillFlags.ANIMALS;
int killed = player.getWorld().killMobs(origin, radius, flags);
player.print("Killed " + killed + " mobs.");