From 107149bd076cdc124db3ef0f8d752ab064d33348 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 28 Nov 2011 05:17:05 +0000 Subject: [PATCH] Fixed Enchantments being lost on inventory.setItem By: Nathan Adams --- .../java/org/bukkit/craftbukkit/inventory/CraftInventory.java | 4 ++-- .../java/org/bukkit/craftbukkit/inventory/CraftItemStack.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index ae0c1f5393..f1d21afa2a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -53,13 +53,13 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { if (item == null || item.getTypeId() <= 0) { mcItems[i] = null; } else { - mcItems[i] = new net.minecraft.server.ItemStack(item.getTypeId(), item.getAmount(), item.getDurability()); + mcItems[i] = CraftItemStack.createNMSItemStack(item); } } } public void setItem(int index, ItemStack item) { - getInventory().setItem(index, (item == null ? null : new net.minecraft.server.ItemStack(item.getTypeId(), item.getAmount(), item.getDurability()))); + getInventory().setItem(index, (item == null ? null : CraftItemStack.createNMSItemStack(item))); } public boolean contains(int materialId) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index e94bf891f9..9ee0a3fea4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -207,4 +207,8 @@ public class CraftItemStack extends ItemStack { public net.minecraft.server.ItemStack getHandle() { return item; } + + public static net.minecraft.server.ItemStack createNMSItemStack(ItemStack original) { + return new CraftItemStack(original).getHandle(); + } }