diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java | 165 | ||||
-rw-r--r-- | Essentials/src/plugin.yml | 2 |
2 files changed, 68 insertions, 99 deletions
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<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) + cleanInventorySelf(server, user, args); + } + } + + @Override + protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + { + if (args.length > 0) + { + if (args[0].contentEquals("*")) + { + cleanInventoryAll(server, sender, args); + } + else if (args[0].trim().length() < 2) { - clearInventory(user, args[0]); + throw new Exception(_("playerNotFound")); } else { - user.getInventory().clear(); + cleanInventoryOthers(server, sender, args); } - user.sendMessage(_("inventoryCleared")); + } + else + { + throw new NotEnoughArgumentsException(); } } - @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + private void cleanInventoryAll(Server server, CommandSender sender, String[] args) throws Exception { - if (args.length < 1) + if (args.length > 1) + { + for (Player onlinePlayer : server.getOnlinePlayers()) + { + clearInventory(onlinePlayer, args[1]); + } + sender.sendMessage("Cleared everyone's inventory"); + } + else { throw new NotEnoughArgumentsException(); } + } - if (args[0].contentEquals("*")) + private void cleanInventoryOthers(Server server, CommandSender user, String[] args) throws Exception + { + List<Player> online = server.matchPlayer(args[0]); + + if (!online.isEmpty()) { - if (args.length > 1) + for (Player p : online) { - for (Player onlinePlayer : server.getOnlinePlayers()) + if (args.length > 1) { - clearInventory(onlinePlayer, args[1]); + clearInventory(p, args[1]); } - sender.sendMessage("Cleared everyone's inventory"); - } - else - { - throw new NotEnoughArgumentsException(); + else + { + p.getInventory().clear(); + } + user.sendMessage(_("inventoryClearedOthers", p.getDisplayName())); } } - else if (args[0].length() >= 3) + else { - List<Player> online = server.matchPlayer(args[0]); + throw new Exception(_("playerNotFound")); + } + } - 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 - { - throw new Exception(_("playerNotFound")); - } + private void cleanInventorySelf(Server server, User user, String[] args) throws Exception + { + if (args.length > 0) + { + clearInventory(user, args[0]); } else { - Player u = server.getPlayer(args[0]); - if (u != null) - { - clearInventory(u, args[0]); - sender.sendMessage(_("inventoryClearedOthers", u.getDisplayName())); - } - else - { - throw new Exception(_("playerNotFound")); - } + user.getInventory().clear(); } + user.sendMessage(_("inventoryCleared")); } - public void clearInventory(Player player, String arg) throws Exception + private void clearInventory(Player player, String arg) throws Exception { - final String[] split = arg.split(":"); - if (arg.contentEquals("*")) + 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: /<command> + usage: /<command> [<player> [item]] aliases: [clear,ci,eci,clearinvent,clean,eclean,eclearinvent,eclearinventory] compass: description: Describes your current bearing. |