3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

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
Dieser Commit ist enthalten in:
TomyLobo 2011-12-06 06:26:12 +01:00
Ursprung 4c9e0a629f
Commit bc3a4377ec
3 geänderte Dateien mit 64 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -32,6 +32,14 @@ import com.sk89q.worldedit.regions.Region;
* @author sk89q * @author sk89q
*/ */
public abstract class LocalWorld { public abstract class LocalWorld {
/**
* Named flags to use as parameters to {@link LocalWorld#killMobs(Vector, int, int)}
*/
public class KillFlags {
public static final int PETS = 1 << 0;
public static final int NPCS = 1 << 1;
}
/** /**
* Random generator. * Random generator.
*/ */
@ -268,17 +276,35 @@ public abstract class LocalWorld {
* @param radius * @param radius
* @return * @return
*/ */
public abstract int killMobs(Vector origin, int radius); @Deprecated
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 flags various flags that determine what to kill
* @return
*/
@Deprecated
public int killMobs(Vector origin, int radius, boolean killPets) {
return killMobs(origin, radius, killPets ? KillFlags.PETS : 0);
}
/** /**
* Kill mobs in an area. * Kill mobs in an area.
* *
* @param origin * @param origin
* @param radius * @param radius
* @param killPets * @param killflags
* @return * @return
*/ */
public abstract int killMobs(Vector origin, int radius, boolean killPets); public int killMobs(Vector origin, double radius, int flags) {
return killMobs(origin, (int) radius, (flags & KillFlags.PETS) != 0);
}
/** /**
* Remove entities in an area. * Remove entities in an area.

Datei anzeigen

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

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*; import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.LocalWorld.KillFlags;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.*; import com.sk89q.worldedit.patterns.*;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
@ -344,11 +345,13 @@ public class UtilityCommands {
@Command( @Command(
aliases = { "butcher" }, aliases = { "butcher" },
usage = "[radius]", usage = "[radius]",
flags = "p", flags = "pn",
desc = "Kill all or nearby mobs", desc = "Kill all or nearby mobs",
help = help =
"Kills nearby mobs, or all mobs if you don't specify a radius.\n" + "Kills nearby mobs, or all mobs if you don't specify a radius.\n" +
"The -p flag makes /butcher also kill pets.", "Flags:" +
" -p also kill pets.\n" +
" -n also kill NPCs.",
min = 0, min = 0,
max = 1 max = 1
) )
@ -361,7 +364,12 @@ public class UtilityCommands {
int radius = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : -1; int radius = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : -1;
Vector origin = session.getPlacementPosition(player); Vector origin = session.getPlacementPosition(player);
int killed = player.getWorld().killMobs(origin, radius, args.hasFlag('p'));
int flags = 0;
if (args.hasFlag('p')) flags |= KillFlags.PETS;
if (args.hasFlag('n')) flags |= KillFlags.NPCS;
int killed = player.getWorld().killMobs(origin, radius, flags);
player.print("Killed " + killed + " mobs."); player.print("Killed " + killed + " mobs.");
} }