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.
This commit is contained in:
graywolf336 2016-03-22 11:11:58 -05:00
parent 0aba5e1569
commit 7f7b688935

View File

@ -37,6 +37,7 @@ import com.graywolf336.jail.enums.Lang;
public class Util { 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 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 static String[] signLines = new String[] { "", "", "", "" };
private final static int inventoryMultipule = 9;
/** /**
* Checks if the first {@link Vector} is inside this region. * Checks if the first {@link Vector} is inside this region.
@ -446,14 +447,16 @@ public class Util {
try { try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); 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 // 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()); inventory.setItem(i, (ItemStack) dataInput.readObject());
} }
dataInput.close(); dataInput.close();
inputStream.close();
return inventory; return inventory;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new IOException("Unable to decode class type.", e); throw new IOException("Unable to decode class type.", e);