From 34edf34ba3710b074a95c8b76434a75ed4b5dd2f Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 27 Nov 2011 06:10:11 +0100 Subject: [PATCH] Using the ItemStack.clone() method --- .../com/earth2me/essentials/FakeInventory.java | 3 +-- .../essentials/InventoryWorkaround.java | 18 ++++++++---------- .../earth2me/essentials/signs/SignTrade.java | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/FakeInventory.java b/Essentials/src/com/earth2me/essentials/FakeInventory.java index 32c653d86..6496fb75b 100644 --- a/Essentials/src/com/earth2me/essentials/FakeInventory.java +++ b/Essentials/src/com/earth2me/essentials/FakeInventory.java @@ -19,8 +19,7 @@ public class FakeInventory implements Inventory { continue; } - this.items[i] = new ItemStack(items[i].getTypeId(), items[i].getAmount(), items[i].getDurability()); - this.items[i].addEnchantments(items[i].getEnchantments()); + this.items[i] = items[i].clone(); } } diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 8b412e72f..bca932ad5 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -101,8 +101,7 @@ public final class InventoryWorkaround { if (combined[j] == null) { - combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability()); - combined[j].addEnchantments(items[i].getEnchantments()); + combined[j] = items[i].clone(); break; } if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments())) @@ -144,8 +143,8 @@ public final class InventoryWorkaround // More than a single stack! if (item.getAmount() > item.getType().getMaxStackSize()) { - ItemStack stack = new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability()); - stack.addEnchantments(item.getEnchantments()); + ItemStack stack = item.clone(); + stack.setAmount(item.getType().getMaxStackSize()); cinventory.setItem(firstFree, stack); item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); } @@ -259,8 +258,7 @@ public final class InventoryWorkaround { if (combined[j] == null) { - combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability()); - combined[j].addEnchantments(items[i].getEnchantments()); + combined[j] = items[i].clone(); break; } if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments())) @@ -325,14 +323,14 @@ public final class InventoryWorkaround final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)]; for (int i = 0; i < stacks; i++) { - final ItemStack stack = new ItemStack(itm.getType(), maxStackSize, itm.getDurability()); - stack.addEnchantments(itm.getEnchantments()); + final ItemStack stack = itm.clone(); + stack.setAmount(maxStackSize); itemStacks[i] = loc.getWorld().dropItem(loc, stack); } if (leftover > 0) { - final ItemStack stack = new ItemStack(itm.getType(), leftover, itm.getDurability()); - stack.addEnchantments(itm.getEnchantments()); + final ItemStack stack = itm.clone(); + stack.setAmount(leftover); itemStacks[stacks] = loc.getWorld().dropItem(loc, stack); } return itemStacks; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 28635796a..7a7031758 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -76,8 +76,8 @@ public class SignTrade extends EssentialsSign amount -= amount % trade.getItemStack().getAmount(); if (amount > 0) { - final ItemStack stack = new ItemStack(player.getItemInHand().getTypeId(), amount, player.getItemInHand().getDurability()); - stack.addEnchantments(player.getItemInHand().getEnchantments()); + final ItemStack stack = player.getItemInHand().clone(); + stack.setAmount(amount); final Trade store = new Trade(stack, ess); addAmount(sign, 2, store, ess); store.charge(player);