Merge pull request #105 from wizjany/master

More command flags
This commit is contained in:
2011-05-25 13:29:29 -07:00
commit 8a4e1fd281
4 changed files with 62 additions and 6 deletions

View File

@ -256,7 +256,7 @@ public abstract class LocalWorld {
} }
/** /**
* Kill mobs in an area. * Kill mobs in an area, excluding pet wolves.
* *
* @param origin * @param origin
* @param radius * @param radius
@ -264,6 +264,16 @@ public abstract class LocalWorld {
*/ */
public abstract int killMobs(Vector origin, int radius); public abstract int killMobs(Vector origin, int radius);
/**
* Kill mobs in an area.
*
* @param origin
* @param radius
* @param killPets
* @return
*/
public abstract int killMobs(Vector origin, int radius, boolean killPets);
/** /**
* Remove entities in an area. * Remove entities in an area.
* *

View File

@ -391,7 +391,7 @@ public class BukkitWorld extends LocalWorld {
} }
/** /**
* Kill mobs in an area. * Kill mobs in an area, excluding tamed wolves.
* *
* @param origin * @param origin
* @param radius -1 for all mobs * @param radius -1 for all mobs
@ -399,12 +399,27 @@ public class BukkitWorld extends LocalWorld {
*/ */
@Override @Override
public int killMobs(Vector origin, int radius) { 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
* @return
*/
@Override
public int killMobs(Vector origin, int radius, boolean killPets) {
int num = 0; int num = 0;
double radiusSq = Math.pow(radius, 2); double radiusSq = Math.pow(radius, 2);
for (LivingEntity ent : world.getLivingEntities()) { for (LivingEntity ent : world.getLivingEntities()) {
if ((ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) if (!killPets && ent instanceof Wolf && ((Wolf) ent).isTamed()) {
&& !(ent instanceof Wolf)) { continue; // tamed wolf
}
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) {
if (radius == -1 if (radius == -1
|| origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) <= radiusSq) { || origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) <= radiusSq) {
ent.remove(); ent.remove();

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter; import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.patterns.*; import com.sk89q.worldedit.patterns.*;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
/** /**
* Region related commands. * Region related commands.
@ -182,6 +183,7 @@ public class RegionCommands {
@Command( @Command(
aliases = {"/move"}, aliases = {"/move"},
usage = "[count] [direction] [leave-id]", usage = "[count] [direction] [leave-id]",
flags = "s",
desc = "Move the contents of the selection", desc = "Move the contents of the selection",
min = 0, min = 0,
max = 3 max = 3
@ -205,6 +207,20 @@ public class RegionCommands {
int affected = editSession.moveCuboidRegion(session.getSelection(player.getWorld()), int affected = editSession.moveCuboidRegion(session.getSelection(player.getWorld()),
dir, count, true, replace); dir, count, true, replace);
if (args.hasFlag('s')) {
try {
Region region = session.getSelection(player.getWorld());
region.expand(dir.multiply(count));
region.contract(dir.multiply(count));
session.getRegionSelector().learnChanges();
session.getRegionSelector().explainRegionAdjust(player, session);
} catch (RegionOperationException e) {
player.printError(e.getMessage());
}
}
player.print(affected + " blocks moved."); player.print(affected + " blocks moved.");
} }
@ -212,7 +228,7 @@ public class RegionCommands {
@Command( @Command(
aliases = {"/stack"}, aliases = {"/stack"},
usage = "[count] [direction]", usage = "[count] [direction]",
flags = "a", flags = "sa",
desc = "Repeat the contents of the selection", desc = "Repeat the contents of the selection",
min = 0, min = 0,
max = 2 max = 2
@ -228,6 +244,20 @@ public class RegionCommands {
int affected = editSession.stackCuboidRegion(session.getSelection(player.getWorld()), int affected = editSession.stackCuboidRegion(session.getSelection(player.getWorld()),
dir, count, !args.hasFlag('a')); dir, count, !args.hasFlag('a'));
if (args.hasFlag('s')) {
try {
Region region = session.getSelection(player.getWorld());
region.expand(dir.multiply(count));
region.contract(dir.multiply(count));
session.getRegionSelector().learnChanges();
session.getRegionSelector().explainRegionAdjust(player, session);
} catch (RegionOperationException e) {
player.printError(e.getMessage());
}
}
player.print(affected + " blocks changed. Undo with //undo"); player.print(affected + " blocks changed. Undo with //undo");
} }

View File

@ -307,6 +307,7 @@ public class UtilityCommands {
@Command( @Command(
aliases = {"butcher"}, aliases = {"butcher"},
usage = "[radius]", usage = "[radius]",
flags = "p",
desc = "Kill all or nearby mobs", desc = "Kill all or nearby mobs",
min = 0, min = 0,
max = 1 max = 1
@ -320,7 +321,7 @@ public class UtilityCommands {
Math.max(1, args.getInteger(0)) : -1; Math.max(1, args.getInteger(0)) : -1;
Vector origin = session.getPlacementPosition(player); Vector origin = session.getPlacementPosition(player);
int killed = player.getWorld().killMobs(origin, radius); int killed = player.getWorld().killMobs(origin, radius, args.hasFlag('p'));
player.print("Killed " + killed + " mobs."); player.print("Killed " + killed + " mobs.");
} }