mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
SPIGOT-4292: Ignore itemstacks with invalid enchants
This commit is contained in:
parent
bfb9131494
commit
82f4b3b1d9
3 changed files with 10 additions and 2 deletions
|
@ -299,7 +299,10 @@ public final class CraftItemStack extends ItemStack {
|
||||||
String id = ((NBTTagCompound) list.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
String id = ((NBTTagCompound) list.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
||||||
int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.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();
|
return result.build();
|
||||||
|
|
|
@ -381,7 +381,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||||
String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
||||||
int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.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) {
|
if (enchant != null) {
|
||||||
enchantments.put(enchant, level);
|
enchantments.put(enchant, level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,11 @@ public final class CraftNamespacedKey {
|
||||||
public 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) {
|
public static NamespacedKey fromString(String string) {
|
||||||
return fromMinecraft(new MinecraftKey(string));
|
return fromMinecraft(new MinecraftKey(string));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue