From 1f5dd50d3f844e7a5725d8640db7ad5e187df439 Mon Sep 17 00:00:00 2001 From: aPunch Date: Sun, 5 Feb 2012 05:26:55 -0600 Subject: [PATCH] items now save in the correct slot, enchantments are saved on inventory close --- src/net/citizensnpcs/npc/NPCInventory.java | 10 ++++++---- src/net/citizensnpcs/trait/Inventory.java | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/net/citizensnpcs/npc/NPCInventory.java b/src/net/citizensnpcs/npc/NPCInventory.java index 866118e6e..1eae9033c 100644 --- a/src/net/citizensnpcs/npc/NPCInventory.java +++ b/src/net/citizensnpcs/npc/NPCInventory.java @@ -6,6 +6,7 @@ import net.minecraft.server.ItemStack; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -40,9 +41,8 @@ public class NPCInventory implements IInventory { return itemstack; } else { ItemStack itemstack = contents[i].a(j); - if (contents[i].count == 0) { + if (contents[i].count == 0) contents[i] = null; - } return itemstack; } } @@ -80,9 +80,11 @@ public class NPCInventory implements IInventory { // close org.bukkit.inventory.ItemStack[] bukkitItems = new org.bukkit.inventory.ItemStack[size]; int index = 0; - for (ItemStack item : contents) + for (ItemStack item : contents) { if (item != null) - bukkitItems[index++] = new org.bukkit.inventory.ItemStack(item.id, item.count, (short) item.getData()); + bukkitItems[index] = new CraftItemStack(item); + index++; + } npc.getTrait(net.citizensnpcs.trait.Inventory.class).setContents(bukkitItems); } diff --git a/src/net/citizensnpcs/trait/Inventory.java b/src/net/citizensnpcs/trait/Inventory.java index 963a01e49..57be6c3a7 100644 --- a/src/net/citizensnpcs/trait/Inventory.java +++ b/src/net/citizensnpcs/trait/Inventory.java @@ -39,9 +39,13 @@ public class Inventory implements Trait { @Override public void save(DataKey key) { int index = 0; - for (ItemStack item : contents) + for (ItemStack item : contents) { + // Clear previous items to avoid conflicts + key.removeKey(String.valueOf(index)); if (item != null) - saveItem(item, key.getRelative(String.valueOf(index++))); + saveItem(item, key.getRelative(String.valueOf(index))); + index++; + } } private ItemStack[] parseContents(DataKey key) throws NPCLoadException {