diff --git a/src/main/java/org/kitteh/tim/Tim.java b/src/main/java/org/kitteh/tim/Tim.java index 04848e4..d7884a6 100644 --- a/src/main/java/org/kitteh/tim/Tim.java +++ b/src/main/java/org/kitteh/tim/Tim.java @@ -140,6 +140,8 @@ private int getEnchantmentLevel(CommandContext commandContext) throws CommandExc level = Integer.parseInt(levelString); if (level < 1) { throw new CommandException(this.getErrorText("Enchantment level has to be greater than 0")); + } else if (level > Short.MAX_VALUE) { + throw new CommandException(this.getErrorText("Enchantment level can't be higher than " + Short.MAX_VALUE)); } return level; } catch (NumberFormatException e) { @@ -163,7 +165,9 @@ private void enchant(Player player, Enchantment enchantment, int level) throws C ItemStack item = player.getItemInHand().orElseThrow(() -> new CommandException(this.getErrorText("You need to be holding an item to enchant it!"))); item.transform(Keys.ITEM_ENCHANTMENTS, list -> { List newList = new LinkedList<>(); - list.stream().filter(ench -> ench.getEnchantment() != enchantment).forEach(newList::add); + if (list != null) { + list.stream().filter(ench -> ench.getEnchantment() != enchantment).forEach(newList::add); + } newList.add(new ItemEnchantment(enchantment, level)); return newList; });