Revert to the old behavior of oversized stacks. We might remove or change this in the future.

This commit is contained in:
snowleo 2011-11-27 10:59:28 +01:00
parent 0c0c9573be
commit d5db9d404a
3 changed files with 10 additions and 5 deletions

View file

@ -80,6 +80,11 @@ public final class InventoryWorkaround
} }
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items) public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
{
return addItem(cinventory, forceDurability, false, null, items);
}
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final IEssentials ess, final ItemStack... items)
{ {
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>(); final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
@ -142,10 +147,10 @@ public final class InventoryWorkaround
else else
{ {
// More than a single stack! // More than a single stack!
if (item.getAmount() > item.getType().getMaxStackSize()) if (item.getAmount() > (dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize()))
{ {
ItemStack stack = item.clone(); ItemStack stack = item.clone();
stack.setAmount(item.getType().getMaxStackSize()); stack.setAmount(dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize());
EnchantmentFix.setItem(cinventory, firstFree, stack); EnchantmentFix.setItem(cinventory, firstFree, stack);
item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); item.setAmount(item.getAmount() - item.getType().getMaxStackSize());
} }
@ -164,7 +169,7 @@ public final class InventoryWorkaround
final int amount = item.getAmount(); final int amount = item.getAmount();
final int partialAmount = partialItem.getAmount(); final int partialAmount = partialItem.getAmount();
final int maxAmount = partialItem.getType().getMaxStackSize(); final int maxAmount = dontBreakStacks ? ess.getSettings().getDefaultStackSize() : partialItem.getType().getMaxStackSize();
// Check if it fully fits // Check if it fully fits
if (amount + partialAmount <= maxAmount) if (amount + partialAmount <= maxAmount)

View file

@ -77,7 +77,7 @@ public class Commandgive extends EssentialsCommand
final User giveTo = getPlayer(server, args, 0); final User giveTo = getPlayer(server, args, 0);
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + "."); sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
InventoryWorkaround.addItem(giveTo.getInventory(), true, stack); InventoryWorkaround.addItem(giveTo.getInventory(), true, true, ess, stack);
giveTo.updateInventory(); giveTo.updateInventory();
} }
} }

View file

@ -72,7 +72,7 @@ public class Commanditem extends EssentialsCommand
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName)); user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
InventoryWorkaround.addItem(user.getInventory(), true, stack); InventoryWorkaround.addItem(user.getInventory(), true, true, ess, stack);
user.updateInventory(); user.updateInventory();
} }
} }