summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-08-20 12:49:31 +1000
committermd_5 <git@md-5.net>2018-08-20 12:49:36 +1000
commit82f4b3b1d97e08fb649a5e461aa98e335021fe26 (patch)
tree80d07719046232cf1ddf28390cf08da4bcf31056 /src/main/java/org/bukkit
parentbfb9131494176498e2444f7ac69bdc924192ee2e (diff)
downloadcraftbukkit-82f4b3b1d97e08fb649a5e461aa98e335021fe26.tar
craftbukkit-82f4b3b1d97e08fb649a5e461aa98e335021fe26.tar.gz
craftbukkit-82f4b3b1d97e08fb649a5e461aa98e335021fe26.tar.lz
craftbukkit-82f4b3b1d97e08fb649a5e461aa98e335021fe26.tar.xz
craftbukkit-82f4b3b1d97e08fb649a5e461aa98e335021fe26.zip
SPIGOT-4292: Ignore itemstacks with invalid enchants
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java5
3 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index f5a39c2e..ef4c49f1 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -299,7 +299,10 @@ public final class CraftItemStack extends ItemStack {
String id = ((NBTTagCompound) list.get(i)).getString(ENCHANTMENTS_ID.NBT);
int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT);
- result.put(Enchantment.getByKey(CraftNamespacedKey.fromString(id)), level);
+ Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(id));
+ if (enchant != null) {
+ result.put(enchant, level);
+ }
}
return result.build();
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index e0f28caa..77266427 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -381,7 +381,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT);
int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT);
- Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromString(id));
+ Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(id));
if (enchant != null) {
enchantments.put(enchant, level);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java b/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
index d8831f61..03d2392a 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
@@ -8,6 +8,11 @@ public final class CraftNamespacedKey {
public CraftNamespacedKey() {
}
+ public static NamespacedKey fromStringOrNull(String string) {
+ MinecraftKey minecraft = MinecraftKey.a(string);
+ return (minecraft == null) ? null : fromMinecraft(minecraft);
+ }
+
public static NamespacedKey fromString(String string) {
return fromMinecraft(new MinecraftKey(string));
}