From 2fd3f8d299fdee827de90a999c5a4c9fd6eefeb9 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Thu, 21 Apr 2011 00:24:27 -0400 Subject: [PATCH] Reapplying changes lost with our new system in CraftInventory and CraftInventoryPlayer. --- .../craftbukkit/inventory/CraftInventory.java | 22 +++++++++---------- .../inventory/CraftInventoryPlayer.java | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index eee59f9816..bba47de784 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -26,16 +26,16 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { return getInventory().getName(); } - public CraftItemStack getItem(int index) { + public ItemStack getItem(int index) { return new CraftItemStack(getInventory().getItem(index)); } - public CraftItemStack[] getContents() { - CraftItemStack[] items = new CraftItemStack[getSize()]; + public ItemStack[] getContents() { + ItemStack[] items = new ItemStack[getSize()]; net.minecraft.server.ItemStack[] mcItems = getInventory().getContents(); for (int i = 0; i < mcItems.length; i++ ) { - items[i] = new CraftItemStack(mcItems[i]); + items[i] = mcItems[i] == null ? null : new CraftItemStack(mcItems[i]); } return items; @@ -64,7 +64,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { public boolean contains(int materialId) { for (ItemStack item: getContents()) { - if (item.getTypeId() == materialId) { + if (item != null && item.getTypeId() == materialId) { return true; } } @@ -90,11 +90,11 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { public boolean contains(int materialId, int amount) { int amt = 0; for (ItemStack item: getContents()) { - if (item.getTypeId() == materialId && item.getAmount() >= amount) { - return true; + if (item != null && item.getTypeId() == materialId) { + amt += item.getAmount(); } } - return false; + return amt >= amount; } public boolean contains(Material material, int amount) { @@ -107,11 +107,11 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } int amt = 0; for (ItemStack i: getContents()) { - if (item.equals(i) && item.getAmount() >= amount) { - return true; + if (item.equals(i)) { + amt += item.getAmount(); } } - return false; + return amt >= amount; } public HashMap all(int materialId) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index d721686fc2..5d97b4cf99 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -30,19 +30,19 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent return getInventory().itemInHandIndex; } - public CraftItemStack getHelmet() { + public ItemStack getHelmet() { return getItem( getSize() + 3 ); } - public CraftItemStack getChestplate() { + public ItemStack getChestplate() { return getItem( getSize() + 2 ); } - public CraftItemStack getLeggings() { + public ItemStack getLeggings() { return getItem( getSize() + 1 ); } - public CraftItemStack getBoots() { + public ItemStack getBoots() { return getItem( getSize() + 0 ); }