Using the ItemStack.clone() method

This commit is contained in:
snowleo 2011-11-27 06:10:11 +01:00
parent f250a107e4
commit 34edf34ba3
3 changed files with 11 additions and 14 deletions

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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);