This commit is contained in:
GunfighterJ 2013-01-27 14:20:59 -06:00
commit ce7d83adb6
2 changed files with 77 additions and 108 deletions

View File

@ -23,85 +23,50 @@ public class Commandclearinventory extends EssentialsCommand
{ {
if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others")) 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[0].contentEquals("*") && user.isAuthorized("essentials.clearinventory.all"))
{ {
if (args.length > 1) cleanInventoryAll(server, user, args);
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
} }
user.sendMessage("Cleared everyone's inventory"); else if (args[0].trim().length() < 2)
{
cleanInventorySelf(server, user, args);
} }
else else
{ {
throw new NotEnoughArgumentsException(); cleanInventoryOthers(server, user, args);
}
}
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();
}
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
} }
} }
else else
{ {
clearInventory(user, args[0]); cleanInventorySelf(server, user, args);
user.sendMessage(_("inventoryCleared"));
}
}
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"));
}
}
}
else
{
if (args.length > 0)
{
clearInventory(user, args[0]);
}
else
{
user.getInventory().clear();
}
user.sendMessage(_("inventoryCleared"));
} }
} }
@Override @Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{ {
if (args.length < 1) if (args.length > 0)
{
if (args[0].contentEquals("*"))
{
cleanInventoryAll(server, sender, args);
}
else if (args[0].trim().length() < 2)
{
throw new Exception(_("playerNotFound"));
}
else
{
cleanInventoryOthers(server, sender, args);
}
}
else
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
}
if (args[0].contentEquals("*")) private void cleanInventoryAll(Server server, CommandSender sender, String[] args) throws Exception
{ {
if (args.length > 1) if (args.length > 1)
{ {
@ -116,7 +81,8 @@ public class Commandclearinventory extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
} }
else if (args[0].length() >= 3)
private void cleanInventoryOthers(Server server, CommandSender user, String[] args) throws Exception
{ {
List<Player> online = server.matchPlayer(args[0]); List<Player> online = server.matchPlayer(args[0]);
@ -132,7 +98,7 @@ public class Commandclearinventory extends EssentialsCommand
{ {
p.getInventory().clear(); p.getInventory().clear();
} }
sender.sendMessage(_("inventoryClearedOthers", p.getDisplayName())); user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
} }
} }
else else
@ -140,37 +106,40 @@ public class Commandclearinventory extends EssentialsCommand
throw new Exception(_("playerNotFound")); throw new Exception(_("playerNotFound"));
} }
} }
else
{
Player u = server.getPlayer(args[0]);
if (u != null)
{
clearInventory(u, args[0]);
sender.sendMessage(_("inventoryClearedOthers", u.getDisplayName()));
}
else
{
throw new Exception(_("playerNotFound"));
}
}
}
public void clearInventory(Player player, String arg) throws Exception private void cleanInventorySelf(Server server, User user, String[] args) throws Exception
{ {
final String[] split = arg.split(":"); if (args.length > 0)
if (arg.contentEquals("*")) {
clearInventory(user, args[0]);
}
else
{
user.getInventory().clear();
}
user.sendMessage(_("inventoryCleared"));
}
private void clearInventory(Player player, String arg) throws Exception
{
if (arg.equalsIgnoreCase("*"))
{ {
player.getInventory().clear(); player.getInventory().clear();
} }
else else
{ {
final String[] split = arg.split(":");
final ItemStack item = ess.getItemDb().get(split[0]); final ItemStack item = ess.getItemDb().get(split[0]);
final int type = item.getTypeId(); final int type = item.getTypeId();
if (split.length > 1 && Util.isInt(arg.replace(":", ""))) if (split.length > 1 && Util.isInt(split[1]))
{ {
player.getInventory().clear(type, Integer.parseInt(split[1])); player.getInventory().clear(type, Integer.parseInt(split[1]));
} }
else if (split.length > 1 && split[1].equalsIgnoreCase("*"))
{
player.getInventory().clear(type, -1);
}
else else
{ {
if (Util.isInt(split[0])) if (Util.isInt(split[0]))

View File

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