diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 0adb7cf04..51b7455bf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -23,154 +23,123 @@ 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 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 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 { - final String[] split = arg.split(":"); - if (arg.contentEquals("*")) + 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 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 + { + if (arg.equalsIgnoreCase("*")) { player.getInventory().clear(); } else { + final String[] split = arg.split(":"); final ItemStack item = ess.getItemDb().get(split[0]); 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])); } + else if (split.length > 1 && split[1].equalsIgnoreCase("*")) + { + player.getInventory().clear(type, -1); + } else { if (Util.isInt(split[0])) diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 0a43b2901..ca3cbc040 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -61,7 +61,7 @@ commands: aliases: [eburn] clearinventory: description: Clear all items in your inventory. - usage: / + usage: / [ [item]] aliases: [clear,ci,eci,clearinvent,clean,eclean,eclearinvent,eclearinventory] compass: description: Describes your current bearing.