From 7f7b688935d2e012c1cceea70ba60f18383318cc Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 22 Mar 2016 11:11:58 -0500 Subject: [PATCH] Fixes #112 and fixes #113. Spigot 1.9 changed how a player's inventory is handled. They now include the player's armor and off hand content, which makes creating an inventory directly from a player's inventory impossible without working with it. --- src/main/java/com/graywolf336/jail/Util.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/Util.java b/src/main/java/com/graywolf336/jail/Util.java index 0b01bc1..01276bd 100644 --- a/src/main/java/com/graywolf336/jail/Util.java +++ b/src/main/java/com/graywolf336/jail/Util.java @@ -37,6 +37,7 @@ import com.graywolf336.jail.enums.Lang; public class Util { private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(m(?:inute)?s?|h(?:ours?)?|d(?:ays?)?|s(?:econd)?s?)?$", Pattern.CASE_INSENSITIVE); private static String[] signLines = new String[] { "", "", "", "" }; + private final static int inventoryMultipule = 9; /** * Checks if the first {@link Vector} is inside this region. @@ -446,14 +447,16 @@ public class Util { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); - Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt()); + int size = dataInput.readInt(); + Inventory inventory = Bukkit.getServer().createInventory(null, (int)Math.ceil((double)size / inventoryMultipule) * inventoryMultipule); // Read the serialized inventory - for (int i = 0; i < inventory.getSize(); i++) { + for (int i = 0; i < size; i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); + inputStream.close(); return inventory; } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e);