mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Using the ItemStack.clone() method
This commit is contained in:
parent
f250a107e4
commit
34edf34ba3
@ -19,8 +19,7 @@ public class FakeInventory implements Inventory
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.items[i] = new ItemStack(items[i].getTypeId(), items[i].getAmount(), items[i].getDurability());
|
this.items[i] = items[i].clone();
|
||||||
this.items[i].addEnchantments(items[i].getEnchantments());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +101,7 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
if (combined[j] == null)
|
if (combined[j] == null)
|
||||||
{
|
{
|
||||||
combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability());
|
combined[j] = items[i].clone();
|
||||||
combined[j].addEnchantments(items[i].getEnchantments());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments()))
|
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!
|
// More than a single stack!
|
||||||
if (item.getAmount() > item.getType().getMaxStackSize())
|
if (item.getAmount() > item.getType().getMaxStackSize())
|
||||||
{
|
{
|
||||||
ItemStack stack = new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability());
|
ItemStack stack = item.clone();
|
||||||
stack.addEnchantments(item.getEnchantments());
|
stack.setAmount(item.getType().getMaxStackSize());
|
||||||
cinventory.setItem(firstFree, stack);
|
cinventory.setItem(firstFree, stack);
|
||||||
item.setAmount(item.getAmount() - item.getType().getMaxStackSize());
|
item.setAmount(item.getAmount() - item.getType().getMaxStackSize());
|
||||||
}
|
}
|
||||||
@ -259,8 +258,7 @@ public final class InventoryWorkaround
|
|||||||
{
|
{
|
||||||
if (combined[j] == null)
|
if (combined[j] == null)
|
||||||
{
|
{
|
||||||
combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability());
|
combined[j] = items[i].clone();
|
||||||
combined[j].addEnchantments(items[i].getEnchantments());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments()))
|
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)];
|
final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
|
||||||
for (int i = 0; i < stacks; i++)
|
for (int i = 0; i < stacks; i++)
|
||||||
{
|
{
|
||||||
final ItemStack stack = new ItemStack(itm.getType(), maxStackSize, itm.getDurability());
|
final ItemStack stack = itm.clone();
|
||||||
stack.addEnchantments(itm.getEnchantments());
|
stack.setAmount(maxStackSize);
|
||||||
itemStacks[i] = loc.getWorld().dropItem(loc, stack);
|
itemStacks[i] = loc.getWorld().dropItem(loc, stack);
|
||||||
}
|
}
|
||||||
if (leftover > 0)
|
if (leftover > 0)
|
||||||
{
|
{
|
||||||
final ItemStack stack = new ItemStack(itm.getType(), leftover, itm.getDurability());
|
final ItemStack stack = itm.clone();
|
||||||
stack.addEnchantments(itm.getEnchantments());
|
stack.setAmount(leftover);
|
||||||
itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
|
itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
|
||||||
}
|
}
|
||||||
return itemStacks;
|
return itemStacks;
|
||||||
|
@ -76,8 +76,8 @@ public class SignTrade extends EssentialsSign
|
|||||||
amount -= amount % trade.getItemStack().getAmount();
|
amount -= amount % trade.getItemStack().getAmount();
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
{
|
{
|
||||||
final ItemStack stack = new ItemStack(player.getItemInHand().getTypeId(), amount, player.getItemInHand().getDurability());
|
final ItemStack stack = player.getItemInHand().clone();
|
||||||
stack.addEnchantments(player.getItemInHand().getEnchantments());
|
stack.setAmount(amount);
|
||||||
final Trade store = new Trade(stack, ess);
|
final Trade store = new Trade(stack, ess);
|
||||||
addAmount(sign, 2, store, ess);
|
addAmount(sign, 2, store, ess);
|
||||||
store.charge(player);
|
store.charge(player);
|
||||||
|
Loading…
Reference in New Issue
Block a user