From 6bb1f087e7d12f3a30ebcb45c6cf95608d0b351d Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 27 Apr 2019 12:50:43 +1000 Subject: [PATCH] Loosen restrictions on inventory sizing Allows creating (but not opening) inventories created eg via Bukkit.createInventory(..., InventoryType.PLAYER); --- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++-- .../java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java | 2 +- .../bukkit/craftbukkit/inventory/CraftInventoryCustom.java | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 459bf23cc4..594ee255c7 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1503,13 +1503,13 @@ public final class CraftServer implements Server { @Override public Inventory createInventory(InventoryHolder owner, int size) throws IllegalArgumentException { - Validate.isTrue(size % 9 == 0, "Chests must have a size that is a multiple of 9!"); + Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots"); return CraftInventoryCreator.INSTANCE.createInventory(owner, size); } @Override public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException { - Validate.isTrue(size % 9 == 0, "Chests must have a size that is a multiple of 9!"); + Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots"); return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index a7b495c7ad..ebd55c4f8f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -333,7 +333,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { customSize = Containers.GENERIC_9X6; break; default: - throw new IllegalArgumentException("Unsupported custom size " + inventory.getSize()); + throw new IllegalArgumentException("Unsupported custom inventory size " + inventory.getSize()); } openCustomInventory(inventory, player, customSize); break; diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java index a0a86661df..0f4975b40a 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java @@ -55,7 +55,6 @@ public class CraftInventoryCustom extends CraftInventory { public MinecraftInventory(InventoryHolder owner, int size, String title) { Validate.notNull(title, "Title cannot be null"); - Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots"); this.items = NonNullList.a(size, ItemStack.a); this.title = title; this.viewers = new ArrayList();