Catch NPE in /powertool, also cleanup

This commit is contained in:
snowleo 2011-08-30 01:14:03 +02:00
parent 12e3eb1a23
commit 17e11adf9a

View File

@ -17,17 +17,17 @@ public class Commandpowertool extends EssentialsCommand
} }
@Override @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(); final ItemStack itemStack = user.getItemInHand();
List<String> powertools = user.getPowertool(is); if (itemStack == null || itemStack.getType() == Material.AIR)
if (is == null || is.getType() == Material.AIR)
{ {
throw new Exception(Util.i18n("powerToolAir")); 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); String command = getFinalArg(args, 0);
List<String> powertools = user.getPowertool(itemStack);
if (command != null && !command.isEmpty()) if (command != null && !command.isEmpty())
{ {
if (command.equalsIgnoreCase("l:")) if (command.equalsIgnoreCase("l:"))
@ -86,11 +86,14 @@ public class Commandpowertool extends EssentialsCommand
} }
} }
else else
{
if (powertools != null)
{ {
powertools.clear(); powertools.clear();
}
user.sendMessage(Util.format("powerToolRemoveAll", itemName)); user.sendMessage(Util.format("powerToolRemoveAll", itemName));
} }
user.setPowertool(is, powertools); user.setPowertool(itemStack, powertools);
} }
} }