From 5cb45990cc0e50852ef78581f117e48f6c756121 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 14 Mar 2012 10:00:54 -0400 Subject: [PATCH] [Bleeding] Implemented Inventory.{get,set}MaxStackSize(). Addresses BUKKIT-1076 - Custom inventories also respect this setting now. By: Celtic Minstrel --- .../craftbukkit/inventory/CraftInventory.java | 8 ++++++++ .../inventory/CraftInventoryCustom.java | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index d64df14338..a5ea612df3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -412,4 +412,12 @@ public class CraftInventory implements Inventory { public InventoryHolder getHolder() { return inventory.getOwner(); } + + public int getMaxStackSize() { + return inventory.getMaxStackSize(); + } + + public void setMaxStackSize(int size) { + inventory.setMaxStackSize(size); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java index eb2546e6c9..a53a5c2ddf 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java @@ -27,11 +27,11 @@ public class CraftInventoryCustom extends CraftInventory { static class MinecraftInventory implements IInventory { private ItemStack[] items; - private int maxStack = 64; + private int maxStack = MAX_STACK; private List viewers; private String title; private InventoryType type; - private InventoryHolder owner; // TODO: Constructors to set this + private InventoryHolder owner; public MinecraftInventory(InventoryHolder owner, InventoryType type) { this(owner, type.getDefaultSize(), type.getDefaultTitle()); @@ -41,7 +41,7 @@ public class CraftInventoryCustom extends CraftInventory { public MinecraftInventory(InventoryHolder owner, int size) { this(owner, size, "Chest"); } - + public MinecraftInventory(InventoryHolder owner, int size, String title) { this.items = new ItemStack[size]; this.title = title; @@ -89,6 +89,9 @@ public class CraftInventoryCustom extends CraftInventory { public void setItem(int i, ItemStack itemstack) { items[i] = itemstack; + if (itemstack != null && this.getMaxStackSize() > 0 && itemstack.count > this.getMaxStackSize()) { + itemstack.count = this.getMaxStackSize(); + } } public String getName() { @@ -99,6 +102,10 @@ public class CraftInventoryCustom extends CraftInventory { return maxStack; } + public void setMaxStackSize(int size) { + maxStack = size; + } + public void update() {} public boolean a(EntityHuman entityhuman) { @@ -120,7 +127,7 @@ public class CraftInventoryCustom extends CraftInventory { public List getViewers() { return viewers; } - + public InventoryType getType() { return type; }