mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
parent
6d3e1b862e
commit
1c03cdb4d0
2 changed files with 41 additions and 21 deletions
|
@ -1,19 +1,13 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import java.util.Locale;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Boat;
|
import org.bukkit.entity.*;
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
public class Commandremove extends EssentialsCommand
|
public class Commandremove extends EssentialsCommand
|
||||||
|
@ -23,6 +17,7 @@ public class Commandremove extends EssentialsCommand
|
||||||
super("remove");
|
super("remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum ToRemove
|
private enum ToRemove
|
||||||
{
|
{
|
||||||
DROPS,
|
DROPS,
|
||||||
|
@ -34,17 +29,18 @@ public class Commandremove extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
World world;
|
ToRemove toRemove;
|
||||||
int radius = -1;
|
final World world = user.getWorld();
|
||||||
if (sender instanceof Player)
|
int radius = 0;
|
||||||
|
|
||||||
|
if (args.length < 2)
|
||||||
{
|
{
|
||||||
world = ((Player)sender).getWorld();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
radius = Integer.parseInt(args[1]);
|
radius = Integer.parseInt(args[1]);
|
||||||
|
@ -54,10 +50,29 @@ public class Commandremove extends EssentialsCommand
|
||||||
throw new Exception(_("numberRequired"));
|
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)
|
if (world == null)
|
||||||
{
|
{
|
||||||
throw new Exception(_("invalidWorld"));
|
throw new Exception(_("invalidWorld"));
|
||||||
|
@ -71,14 +86,19 @@ public class Commandremove extends EssentialsCommand
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException(); //TODO: translate and list types
|
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;
|
int removed = 0;
|
||||||
for (Chunk chunk : world.getLoadedChunks())
|
for (Chunk chunk : world.getLoadedChunks())
|
||||||
{
|
{
|
||||||
for (Entity e : chunk.getEntities())
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +153,6 @@ public class Commandremove extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(_("kill", removed));
|
sender.sendMessage(_("removed", removed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ commands:
|
||||||
aliases: [erealname]
|
aliases: [erealname]
|
||||||
remove:
|
remove:
|
||||||
description: Removes entities in your world
|
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]
|
aliases: [eremove]
|
||||||
repair:
|
repair:
|
||||||
description: Repairs the durability of all or one item.
|
description: Repairs the durability of all or one item.
|
||||||
|
|
Loading…
Reference in a new issue