diff --git a/src/main/java/org/kitteh/tim/Tim.java b/src/main/java/org/kitteh/tim/Tim.java index 9f6a64e..9ee1ba5 100644 --- a/src/main/java/org/kitteh/tim/Tim.java +++ b/src/main/java/org/kitteh/tim/Tim.java @@ -141,6 +141,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) { @@ -164,7 +166,9 @@ private void enchant(Player player, Enchantment enchantment, int level) throws C ItemStack item = player.getItemInHand(HandTypes.MAIN_HAND).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; });