diff options
author | snowleo <schneeleo@gmail.com> | 2011-08-30 01:14:03 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-08-30 01:14:03 +0200 |
commit | c155374e55bebde5ceceeb9257705537cf6e85ed (patch) | |
tree | 562ea21545944d6923b7fb0296e851081e3f1836 | |
parent | b1bb8c48fc855b0267316e1795bb5dfca43c102c (diff) | |
download | Essentials-c155374e55bebde5ceceeb9257705537cf6e85ed.tar Essentials-c155374e55bebde5ceceeb9257705537cf6e85ed.tar.gz Essentials-c155374e55bebde5ceceeb9257705537cf6e85ed.tar.lz Essentials-c155374e55bebde5ceceeb9257705537cf6e85ed.tar.xz Essentials-c155374e55bebde5ceceeb9257705537cf6e85ed.zip |
Catch NPE in /powertool, also cleanup
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 742535a77..b4977167f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -17,17 +17,17 @@ public class Commandpowertool extends EssentialsCommand } @Override - protected void run(Server server, User user, String commandLabel, String[] args) throws Exception + protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - ItemStack is = user.getItemInHand(); - List<String> powertools = user.getPowertool(is); - if (is == null || is.getType() == Material.AIR) + final ItemStack itemStack = user.getItemInHand(); + if (itemStack == null || itemStack.getType() == Material.AIR) { throw new Exception(Util.i18n("powerToolAir")); } - String itemName = is.getType().toString().toLowerCase().replaceAll("_", " "); + final String itemName = itemStack.getType().toString().toLowerCase().replaceAll("_", " "); String command = getFinalArg(args, 0); + List<String> powertools = user.getPowertool(itemStack); if (command != null && !command.isEmpty()) { if (command.equalsIgnoreCase("l:")) @@ -66,7 +66,7 @@ public class Commandpowertool extends EssentialsCommand if (command.startsWith("a:")) { command = command.substring(2); - if(powertools.contains(command)) + if (powertools.contains(command)) { throw new Exception(Util.format("powerToolAlreadySet", command, itemName)); } @@ -87,10 +87,13 @@ public class Commandpowertool extends EssentialsCommand } else { - powertools.clear(); + if (powertools != null) + { + powertools.clear(); + } user.sendMessage(Util.format("powerToolRemoveAll", itemName)); } - user.setPowertool(is, powertools); + user.setPowertool(itemStack, powertools); } } |