From d603539842fe24dc1b37130e47fafe734a542a69 Mon Sep 17 00:00:00 2001 From: BlackHole Date: Wed, 28 Jun 2017 18:37:22 +0200 Subject: SPIGOT-3387: Prevent null enchantments in ItemMeta --- src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index ec923673..8d82c4dc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -566,10 +566,12 @@ class CraftMetaItem implements ItemMeta, Repairable { } public boolean hasEnchant(Enchantment ench) { + Validate.notNull(ench, "Enchantment cannot be null"); return hasEnchants() && enchantments.containsKey(ench); } public int getEnchantLevel(Enchantment ench) { + Validate.notNull(ench, "Enchantment cannot be null"); Integer level = hasEnchants() ? enchantments.get(ench) : null; if (level == null) { return 0; @@ -582,6 +584,7 @@ class CraftMetaItem implements ItemMeta, Repairable { } public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) { + Validate.notNull(ench, "Enchantment cannot be null"); if (enchantments == null) { enchantments = new HashMap(4); } @@ -594,6 +597,7 @@ class CraftMetaItem implements ItemMeta, Repairable { } public boolean removeEnchant(Enchantment ench) { + Validate.notNull(ench, "Enchantment cannot be null"); return hasEnchants() && enchantments.remove(ench) != null; } -- cgit v1.2.3