Less use of sqrt

This commit is contained in:
snowleo 2011-12-04 22:01:50 +01:00
parent dd84f5c331
commit d9c773270b
2 changed files with 9 additions and 3 deletions

View File

@ -78,6 +78,9 @@ public class Commandbutcher extends EssentialsCommand
world = ess.getWorld(args[1]); world = ess.getWorld(args[1]);
} }
} }
if (radius >=0) {
radius *= radius;
}
String killType = type.toLowerCase(); String killType = type.toLowerCase();
int numKills = 0; int numKills = 0;
for (Chunk chunk : world.getLoadedChunks()) for (Chunk chunk : world.getLoadedChunks())
@ -86,7 +89,7 @@ public class Commandbutcher extends EssentialsCommand
{ {
if (sender instanceof Player) if (sender instanceof Player)
{ {
if (((Player)sender).getLocation().distance(entity.getLocation()) > radius && radius >= 0) if (((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius && radius >= 0)
{ {
continue; continue;
} }

View File

@ -89,16 +89,19 @@ public class Commandremove extends EssentialsCommand
removeEntities(sender, world, toRemove, 0); removeEntities(sender, world, toRemove, 0);
} }
protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, final int radius) throws Exception protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, int radius) throws Exception
{ {
int removed = 0; int removed = 0;
if (radius > 0) {
radius*=radius;
}
for (Chunk chunk : world.getLoadedChunks()) for (Chunk chunk : world.getLoadedChunks())
{ {
for (Entity e : chunk.getEntities()) for (Entity e : chunk.getEntities())
{ {
if (radius > 0) if (radius > 0)
{ {
if (((Player)sender).getLocation().distance(e.getLocation()) > radius) if (((Player)sender).getLocation().distanceSquared(e.getLocation()) > radius)
{ {
continue; continue;
} }