diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 26b090861a..d7ad8a5021 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -84,12 +84,12 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { return false; } - public HashMap all(int materialId) { - HashMap slots = new HashMap(); + public HashMap all(int materialId) { + HashMap slots = new HashMap(); - ItemStack[] inventory = getContents(); + CraftItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { - ItemStack item = inventory[i]; + CraftItemStack item = inventory[i]; if (item.getTypeId() == materialId) { slots.put( i, item ); } @@ -97,24 +97,24 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { return slots; } - public HashMap all(Material material) { + public HashMap all(Material material) { return all(material.getId()); } - public HashMap all(ItemStack item) { - HashMap slots = new HashMap(); + public HashMap all(ItemStack item) { + HashMap slots = new HashMap(); - ItemStack[] inventory = getContents(); + CraftItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { if (item.equals(inventory[i])) { - slots.put( i, item ); + slots.put( i, inventory[i] ); } } return slots; } public int first(int materialId) { - ItemStack[] inventory = getContents(); + CraftItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { if (inventory[i].getTypeId() == materialId) { return i; @@ -128,7 +128,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } public int first(ItemStack item) { - ItemStack[] inventory = getContents(); + CraftItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { if (item.equals(inventory[i])) { return i; @@ -142,9 +142,9 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } public int firstPartial(int materialId) { - ItemStack[] inventory = getContents(); + CraftItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { - ItemStack item = inventory[i]; + CraftItemStack item = inventory[i]; if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) { return i; } @@ -161,7 +161,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } public HashMap addItem(ItemStack... items) { - HashMap leftover = new HashMap(); + HashMap leftover = new HashMap(); /* TODO: some optimization * - Create a 'firstPartial' with a 'fromIndex' @@ -187,7 +187,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } else { // More than a single stack! if (item.getAmount() > getMaxItemStack()) { - setItem( firstFree, new ItemStack(item.getTypeId(), getMaxItemStack())); + setItem( firstFree, new CraftItemStack(item.getTypeId(), getMaxItemStack())); item.setAmount(item.getAmount() - getMaxItemStack()); } else { // Just store it @@ -197,7 +197,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory { } } else { // So, apparently it might only partially fit, well lets do just that - ItemStack partialItem = getItem(firstPartial); + CraftItemStack partialItem = getItem(firstPartial); int amount = item.getAmount(); int partialAmount = partialItem.getAmount(); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index af222f3c63..17eb8c09ff 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -62,9 +62,9 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent setItem( getSize() + 3, boots ); } - public ItemStack[] getArmorContents() { + public CraftItemStack[] getArmorContents() { net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents(); - ItemStack[] ret = new ItemStack[mcItems.length]; + CraftItemStack[] ret = new CraftItemStack[mcItems.length]; for (int i = 0; i < mcItems.length; i++ ) { ret[i] = new CraftItemStack(mcItems[i]); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index a08fa55d14..b32f556637 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -7,11 +7,47 @@ public class CraftItemStack extends ItemStack { protected net.minecraft.server.ItemStack item; public CraftItemStack(net.minecraft.server.ItemStack item) { - super(item != null ? item.c : 0, item != null ? item.a : 0, - (byte)(item != null ? item.d : 0)); + super( + item != null ? item.c : 0, + item != null ? item.a : 0, + (byte)(item != null ? item.d : 0) + ); this.item = item; } + /* 'Overwritten' constructors from ItemStack, yay for Java sucking */ + public CraftItemStack(final int type) { + this(type, 0); + } + + public CraftItemStack(final Material type) { + this(type, 0); + } + + public CraftItemStack(final int type, final int amount) { + this(type, amount, (byte) 0); + } + + public CraftItemStack(final Material type, final int amount) { + this(type.getId(), amount); + } + + public CraftItemStack(final int type, final int amount, final byte damage) { + this(type, amount, damage, null); + } + + public CraftItemStack(final Material type, final int amount, final byte damage) { + this(type.getId(), amount, damage); + } + + public CraftItemStack(final Material type, final int amount, final byte damage, final Byte data) { + this(type.getId(), amount, damage, data); + } + + public CraftItemStack(int type, int amount, byte damage, Byte data) { + this(new net.minecraft.server.ItemStack(type, amount, data != null ? data : damage)); + } + /* * Unsure if we have to sync before each of these calls the values in 'item' * are all public.