mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-14 04:01:59 +01:00
Catch NPE in /powertool, also cleanup
This commit is contained in:
parent
12e3eb1a23
commit
17e11adf9a
@ -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:"))
|
||||||
@ -66,7 +66,7 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
if (command.startsWith("a:"))
|
if (command.startsWith("a:"))
|
||||||
{
|
{
|
||||||
command = command.substring(2);
|
command = command.substring(2);
|
||||||
if(powertools.contains(command))
|
if (powertools.contains(command))
|
||||||
{
|
{
|
||||||
throw new Exception(Util.format("powerToolAlreadySet", command, itemName));
|
throw new Exception(Util.format("powerToolAlreadySet", command, itemName));
|
||||||
}
|
}
|
||||||
@ -87,10 +87,13 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
powertools.clear();
|
if (powertools != null)
|
||||||
|
{
|
||||||
|
powertools.clear();
|
||||||
|
}
|
||||||
user.sendMessage(Util.format("powerToolRemoveAll", itemName));
|
user.sendMessage(Util.format("powerToolRemoveAll", itemName));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPowertool(is, powertools);
|
user.setPowertool(itemStack, powertools);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user