From 69e196f79694328abc03f36f3543ba071e56c963 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 1 Mar 2016 19:59:52 +1100 Subject: [PATCH] SPIGOT-1567: Rework setItems to set slots correctly regardless of array reference. --- .../bukkit/craftbukkit/inventory/CraftInventory.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 91b8e4af5f..e6506892be 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -61,17 +61,15 @@ public class CraftInventory implements Inventory { } public void setContents(ItemStack[] items) { - if (getInventory().getContents().length < items.length) { - throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getContents().length + " or less"); + if (getSize() < items.length) { + throw new IllegalArgumentException("Invalid inventory size; expected " + getSize() + " or less"); } - net.minecraft.server.ItemStack[] mcItems = getInventory().getContents(); - - for (int i = 0; i < mcItems.length; i++) { + for (int i = 0; i < getSize(); i++) { if (i >= items.length) { - mcItems[i] = null; + setItem(i, null); } else { - mcItems[i] = CraftItemStack.asNMSCopy(items[i]); + setItem(i, items[i]); } } }