mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-23 08:46:44 +01:00
SPIGOT-3387: Prevent null enchantments in ItemMeta
This commit is contained in:
parent
0481ae963a
commit
d603539842
1 changed files with 4 additions and 0 deletions
|
@ -566,10 +566,12 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEnchant(Enchantment ench) {
|
public boolean hasEnchant(Enchantment ench) {
|
||||||
|
Validate.notNull(ench, "Enchantment cannot be null");
|
||||||
return hasEnchants() && enchantments.containsKey(ench);
|
return hasEnchants() && enchantments.containsKey(ench);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnchantLevel(Enchantment ench) {
|
public int getEnchantLevel(Enchantment ench) {
|
||||||
|
Validate.notNull(ench, "Enchantment cannot be null");
|
||||||
Integer level = hasEnchants() ? enchantments.get(ench) : null;
|
Integer level = hasEnchants() ? enchantments.get(ench) : null;
|
||||||
if (level == null) {
|
if (level == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -582,6 +584,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
|
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
|
||||||
|
Validate.notNull(ench, "Enchantment cannot be null");
|
||||||
if (enchantments == null) {
|
if (enchantments == null) {
|
||||||
enchantments = new HashMap<Enchantment, Integer>(4);
|
enchantments = new HashMap<Enchantment, Integer>(4);
|
||||||
}
|
}
|
||||||
|
@ -594,6 +597,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeEnchant(Enchantment ench) {
|
public boolean removeEnchant(Enchantment ench) {
|
||||||
|
Validate.notNull(ench, "Enchantment cannot be null");
|
||||||
return hasEnchants() && enchantments.remove(ench) != null;
|
return hasEnchants() && enchantments.remove(ench) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue