summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-12-03 21:14:03 +0000
committerKHobbits <rob@khobbits.co.uk>2011-12-03 21:14:03 +0000
commit1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c (patch)
tree63b858b1b9c98235cf019a8bccd60c95e4980300
parent6d3e1b862e8513ad68e9bc5fb576c70a0791355d (diff)
downloadEssentials-1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c.tar
Essentials-1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c.tar.gz
Essentials-1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c.tar.lz
Essentials-1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c.tar.xz
Essentials-1c03cdb4d0a05dc6e5bcf8b1f00113797c24087c.zip
New command /remove
Test #1193
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandremove.java60
-rw-r--r--Essentials/src/plugin.yml2
2 files changed, 41 insertions, 21 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java
index 3839ee81d..33b37ac39 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java
@@ -1,19 +1,13 @@
package com.earth2me.essentials.commands;
-import java.util.Locale;
import static com.earth2me.essentials.I18n._;
+import com.earth2me.essentials.User;
+import java.util.Locale;
import org.bukkit.Chunk;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Boat;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.ExperienceOrb;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Minecart;
-import org.bukkit.entity.Painting;
-import org.bukkit.entity.Player;
-import org.bukkit.entity.Projectile;
+import org.bukkit.entity.*;
public class Commandremove extends EssentialsCommand
@@ -23,6 +17,7 @@ public class Commandremove extends EssentialsCommand
super("remove");
}
+
private enum ToRemove
{
DROPS,
@@ -34,17 +29,18 @@ public class Commandremove extends EssentialsCommand
}
@Override
- protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
+ protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- if (args.length < 2)
+ if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
- World world;
- int radius = -1;
- if (sender instanceof Player)
+ ToRemove toRemove;
+ final World world = user.getWorld();
+ int radius = 0;
+
+ if (args.length < 2)
{
- world = ((Player)sender).getWorld();
try
{
radius = Integer.parseInt(args[1]);
@@ -54,10 +50,29 @@ public class Commandremove extends EssentialsCommand
throw new Exception(_("numberRequired"));
}
}
- else
+
+ try
{
- world = ess.getWorld(args[1]);
+ toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new NotEnoughArgumentsException(); //TODO: translate and list types
}
+
+ removeEntities(user, world, toRemove, radius);
+ }
+
+ @Override
+ protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ {
+ if (args.length < 2)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ World world;
+ world = ess.getWorld(args[1]);
+
if (world == null)
{
throw new Exception(_("invalidWorld"));
@@ -71,14 +86,19 @@ public class Commandremove extends EssentialsCommand
{
throw new NotEnoughArgumentsException(); //TODO: translate and list types
}
+ removeEntities(sender, world, toRemove, 0);
+ }
+
+ protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, final int radius) throws Exception
+ {
int removed = 0;
for (Chunk chunk : world.getLoadedChunks())
{
for (Entity e : chunk.getEntities())
{
- if (sender instanceof Player)
+ if (radius > 0)
{
- if (((Player)sender).getLocation().distance(e.getLocation()) > radius && radius >= 0)
+ if (((Player)sender).getLocation().distance(e.getLocation()) > radius)
{
continue;
}
@@ -133,6 +153,6 @@ public class Commandremove extends EssentialsCommand
}
}
}
- sender.sendMessage(_("kill", removed));
+ sender.sendMessage(_("removed", removed));
}
}
diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml
index cc6620613..48578906f 100644
--- a/Essentials/src/plugin.yml
+++ b/Essentials/src/plugin.yml
@@ -256,7 +256,7 @@ commands:
aliases: [erealname]
remove:
description: Removes entities in your world
- usage: /<command> <drops|arrows|boats|minecarts|xp|paintings> <radius>
+ usage: /<command> <drops|arrows|boats|minecarts|xp|paintings> [radius]
aliases: [eremove]
repair:
description: Repairs the durability of all or one item.