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
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
PAINTINGS
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
final World world = user.getWorld();
|
|
|
|
int radius = 0;
|
|
|
|
|
|
|
|
if (args.length < 2)
|
2011-12-02 19:00:29 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
radius = Integer.parseInt(args[1]);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
throw new Exception(_("numberRequired"));
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(); //TODO: translate and list types
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
|
|
|
|
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]);
|
|
|
|
|
2011-12-02 19:00:29 -05:00
|
|
|
if (world == null)
|
|
|
|
{
|
|
|
|
throw new Exception(_("invalidWorld"));
|
|
|
|
}
|
|
|
|
ToRemove toRemove;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(); //TODO: translate and list types
|
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
removeEntities(sender, world, toRemove, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void removeEntities(final CommandSender sender, final World world, final ToRemove toRemove, final int radius) throws Exception
|
|
|
|
{
|
2011-12-02 19:00:29 -05:00
|
|
|
int removed = 0;
|
|
|
|
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-03 21:14:03 +00:00
|
|
|
if (((Player)sender).getLocation().distance(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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (toRemove == ToRemove.DROPS)
|
|
|
|
{
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 21:14:03 +00:00
|
|
|
sender.sendMessage(_("removed", removed));
|
2011-12-02 19:00:29 -05:00
|
|
|
}
|
|
|
|
}
|