Cleanup /ci addition.

This commit is contained in:
KHobbits 2013-01-27 17:10:07 +00:00
parent c65353350f
commit 9fb42375b8
2 changed files with 71 additions and 106 deletions

View File

@ -23,147 +23,112 @@ public class Commandclearinventory extends EssentialsCommand
{
if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others"))
{
//TODO: Fix fringe user match case.
if (args[0].contentEquals("*") && user.isAuthorized("essentials.clearinventory.all"))
{
if (args.length > 1)
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
}
user.sendMessage("Cleared everyone's inventory");
}
else
{
throw new NotEnoughArgumentsException();
}
cleanInventoryAll(server, user, args);
}
else if (args[0].length() >= 3)
else if (args[0].trim().length() < 2)
{
List<Player> online = server.matchPlayer(args[0]);
if (!online.isEmpty())
{
for (Player p : online)
{
if (args.length > 1)
{
clearInventory(p, args[1]);
}
else
{
p.getInventory().clear();
}
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
}
else
{
clearInventory(user, args[0]);
user.sendMessage(_("inventoryCleared"));
}
cleanInventorySelf(server, user, args);
}
else
{
Player p = server.getPlayer(args[0]);
if (p != null)
{
clearInventory(p, args[1]);
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
else
{
clearInventory(user, args[0]);
user.sendMessage(_("inventoryCleared"));
}
cleanInventoryOthers(server, user, args);
}
}
else
{
if (args.length > 0)
{
clearInventory(user, args[0]);
}
else
{
user.getInventory().clear();
}
user.sendMessage(_("inventoryCleared"));
cleanInventorySelf(server, user, args);
}
}
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
if (args.length > 0)
{
throw new NotEnoughArgumentsException();
}
if (args[0].contentEquals("*"))
{
if (args.length > 1)
if (args[0].contentEquals("*"))
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
}
sender.sendMessage("Cleared everyone's inventory");
cleanInventoryAll(server, sender, args);
}
else
{
throw new NotEnoughArgumentsException();
}
}
else if (args[0].length() >= 3)
{
List<Player> online = server.matchPlayer(args[0]);
if (!online.isEmpty())
{
for (Player p : online)
{
if (args.length > 1)
{
clearInventory(p, args[1]);
}
else
{
p.getInventory().clear();
}
sender.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
}
else
else if (args[0].trim().length() < 2)
{
throw new Exception(_("playerNotFound"));
}
else
{
cleanInventoryOthers(server, sender, args);
}
}
else
{
Player u = server.getPlayer(args[0]);
if (u != null)
{
clearInventory(u, args[0]);
sender.sendMessage(_("inventoryClearedOthers", u.getDisplayName()));
}
else
{
throw new Exception(_("playerNotFound"));
}
throw new NotEnoughArgumentsException();
}
}
public void clearInventory(Player player, String arg) throws Exception
private void cleanInventoryAll(Server server, CommandSender sender, String[] args) throws Exception
{
if (args.length > 1)
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
}
sender.sendMessage("Cleared everyone's inventory");
}
else
{
throw new NotEnoughArgumentsException();
}
}
private void cleanInventoryOthers(Server server, CommandSender user, String[] args) throws Exception
{
List<Player> online = server.matchPlayer(args[0]);
if (!online.isEmpty())
{
for (Player p : online)
{
if (args.length > 1)
{
clearInventory(p, args[1]);
}
else
{
p.getInventory().clear();
}
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
}
else
{
throw new Exception(_("playerNotFound"));
}
}
private void cleanInventorySelf(Server server, User user, String[] args) throws Exception
{
if (args.length > 0)
{
clearInventory(user, args[0]);
}
else
{
user.getInventory().clear();
}
user.sendMessage(_("inventoryCleared"));
}
private void clearInventory(Player player, String arg) throws Exception
{
final String[] split = arg.split(":");
if (arg.contentEquals("*"))
{
player.getInventory().clear();
}
else
{
final String[] split = arg.split(":");
final ItemStack item = ess.getItemDb().get(split[0]);
final int type = item.getTypeId();

View File

@ -61,7 +61,7 @@ commands:
aliases: [eburn]
clearinventory:
description: Clear all items in your inventory.
usage: /<command>
usage: /<command> [<player> [item]]
aliases: [clear,ci,eci,clearinvent,clean,eclean,eclearinvent,eclearinventory]
compass:
description: Describes your current bearing.