Set vault size manually instead of relying on Inventory object. Fixes #366

This commit is contained in:
Trent Hensler
2018-12-15 16:13:40 -08:00
parent d17c606c5f
commit 55cbea8582
3 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<groupId>com.drtshock</groupId> <groupId>com.drtshock</groupId>
<artifactId>PlayerVaultsX</artifactId> <artifactId>PlayerVaultsX</artifactId>
<version>4.0.6</version> <version>4.0.7</version>
<name>PlayerVaultsX</name> <name>PlayerVaultsX</name>
<url>https://www.spigotmc.org/resources/51204/</url> <url>https://www.spigotmc.org/resources/51204/</url>
@@ -16,13 +16,13 @@ import java.io.ByteArrayOutputStream;
*/ */
public class Base64Serialization { public class Base64Serialization {
public static String toBase64(Inventory inventory) { public static String toBase64(Inventory inventory, int size) {
try { try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory // Write the size of the inventory
dataOutput.writeInt(inventory.getSize()); dataOutput.writeInt(size);
// Save every element in the list // Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) { for (int i = 0; i < inventory.getSize(); i++) {
@@ -40,7 +40,7 @@ public class Base64Serialization {
public static String toBase64(ItemStack[] is, int size) { public static String toBase64(ItemStack[] is, int size) {
Inventory inventory = Bukkit.createInventory(null, size); Inventory inventory = Bukkit.createInventory(null, size);
inventory.setContents(is); inventory.setContents(is);
return toBase64(inventory); return toBase64(inventory, size);
} }
public static Inventory fromBase64(String data) { public static Inventory fromBase64(String data) {
@@ -48,7 +48,6 @@ public class Base64Serialization {
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()); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
// Read the serialized inventory // Read the serialized inventory
for (int i = 0; i < inventory.getSize(); i++) { for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, (ItemStack) dataInput.readObject()); inventory.setItem(i, (ItemStack) dataInput.readObject());
@@ -42,7 +42,8 @@ public class VaultManager {
*/ */
public void saveVault(Inventory inventory, UUID target, int number) { public void saveVault(Inventory inventory, UUID target, int number) {
YamlConfiguration yaml = getPlayerVaultFile(target); YamlConfiguration yaml = getPlayerVaultFile(target);
String serialized = Base64Serialization.toBase64(inventory); int size = VaultOperations.getMaxVaultSize(target);
String serialized = Base64Serialization.toBase64(inventory, size);
yaml.set(String.format(VAULTKEY, number), serialized); yaml.set(String.format(VAULTKEY, number), serialized);
saveFileSync(target, yaml); saveFileSync(target, yaml);
} }