2011-12-02 19:00:29 -05:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-12-03 21:14:03 +00:00
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import java.util.Locale;
|
2011-12-02 19:00:29 -05:00
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2011-12-03 21:14:03 +00:00
|
|
|
import org.bukkit.entity.*;
|
2011-12-02 19:00:29 -05:00
|
|
|
|
2012-06-10 19:36:31 +01:00
|
|
|
//Todo: Fix this up
|
2011-12-02 19:00:29 -05:00
|
|
|
public class Commandremove extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandremove()
|
|
|
|
{
|
|
|
|
super("remove");
|
|
|
|
}
|
|
|
|
|
2011-12-03 21:14:03 +00:00
|
|
|
|
2011-12-02 19:00:29 -05:00
|
|
|
private enum ToRemove
|
|
|
|
{
|
|
|
|
DROPS,
|
|
|
|
ARROWS,
|
|
|
|
BOATS,
|
|
|
|
MINECARTS,
|
|
|
|
XP,
|
2013-03-29 22:20:54 -04:00
|
|
|
PAINTINGS,
|
2013-07-15 02:33:15 +01:00
|
|
|
ITEMFRAMES,
|
|
|
|
ENDERCRYSTALS
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-03 21:14:03 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
2011-12-03 21:14:03 +00:00
|
|
|
if (args.length < 1)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
ToRemove toRemove;
|
2013-03-25 16:05:35 +02:00
|
|
|
World world = user.getWorld();
|
2011-12-03 21:14:03 +00:00
|
|
|
int radius = 0;
|
|
|
|
|
2013-03-25 16:05:35 +02:00
|
|
|
if (args.length >= 2)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
radius = Integer.parseInt(args[1]);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
2012-04-04 03:09:27 +01:00
|
|
|
throw new Exception(_("numberRequired"), e);
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
|
|
|
}
|
2013-04-28 04:26:39 +01:00
|
|
|
|
2013-03-25 16:05:35 +02:00
|
|
|
if (args.length >= 3)
|
|
|
|
{
|
|
|
|
world = ess.getWorld(args[2]);
|
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
|
|
|
|
try
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
2011-12-03 21:14:03 +00:00
|
|
|
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e)
|
|
|
|
{
|
2013-04-28 04:26:39 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
toRemove = ToRemove.valueOf(args[0].concat("S").toUpperCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ee)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(ee); //TODO: translate and list types
|
|
|
|
}
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
|
2013-07-07 12:11:57 +01:00
|
|
|
removeEntities(user.getBase(), world, toRemove, radius);
|
2011-12-03 21:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
2013-03-25 16:05:35 +02:00
|
|
|
World world = ess.getWorld(args[1]);
|
2011-12-03 21:14:03 +00:00
|
|
|
|
2011-12-02 19:00:29 -05:00
|
|
|
ToRemove toRemove;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e)
|
|
|
|
{
|
2013-04-28 04:26:39 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
toRemove = ToRemove.valueOf(args[0].concat("S").toUpperCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ee)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(ee); //TODO: translate and list types
|
|
|
|
}
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
removeEntities(sender, world, toRemove, 0);
|
|
|
|
}
|
|
|
|
|
2011-12-04 22:01:50 +01:00
|
|
|
protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, int radius) throws Exception
|
2011-12-03 21:14:03 +00:00
|
|
|
{
|
2011-12-02 19:00:29 -05:00
|
|
|
int removed = 0;
|
2012-04-04 03:09:27 +01:00
|
|
|
if (radius > 0)
|
|
|
|
{
|
|
|
|
radius *= radius;
|
2011-12-04 22:01:50 +01:00
|
|
|
}
|
2011-12-02 19:00:29 -05:00
|
|
|
for (Chunk chunk : world.getLoadedChunks())
|
|
|
|
{
|
|
|
|
for (Entity e : chunk.getEntities())
|
|
|
|
{
|
2011-12-03 21:14:03 +00:00
|
|
|
if (radius > 0)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
2011-12-04 22:01:50 +01:00
|
|
|
if (((Player)sender).getLocation().distanceSquared(e.getLocation()) > radius)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-12-02 20:55:43 -05:00
|
|
|
if (toRemove == ToRemove.DROPS)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
if (e instanceof Item)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (toRemove == ToRemove.ARROWS)
|
|
|
|
{
|
|
|
|
if (e instanceof Projectile)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (toRemove == ToRemove.BOATS)
|
|
|
|
{
|
|
|
|
if (e instanceof Boat)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 19:36:31 +01:00
|
|
|
else if (toRemove == ToRemove.MINECARTS)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
if (e instanceof Minecart)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (toRemove == ToRemove.XP)
|
|
|
|
{
|
|
|
|
if (e instanceof ExperienceOrb)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (toRemove == ToRemove.PAINTINGS)
|
|
|
|
{
|
|
|
|
if (e instanceof Painting)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
2013-03-29 22:20:54 -04:00
|
|
|
else if (toRemove == ToRemove.ITEMFRAMES)
|
|
|
|
{
|
2013-08-07 08:59:47 -07:00
|
|
|
if (e instanceof ItemFrame)
|
2013-03-29 22:20:54 -04:00
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
2013-07-15 02:33:15 +01:00
|
|
|
else if (toRemove == ToRemove.ENDERCRYSTALS)
|
|
|
|
{
|
|
|
|
if (e instanceof EnderCrystal)
|
|
|
|
{
|
|
|
|
e.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
sender.sendMessage(_("removed", removed));
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
|
|
|
}
|