Healthier conversion strategy

This commit is contained in:
mbax
2021-01-01 22:41:14 -05:00
parent 5e3deaa8e2
commit de58a37d2d
5 changed files with 238 additions and 344 deletions
@@ -40,7 +40,7 @@ public class CardboardBoxSerialization {
}
}
private static byte[] writeInventory(ItemStack[] contents) throws IOException {
public static byte[] writeInventory(ItemStack[] contents) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bytes);
out.writeInt(contents.length);
@@ -64,21 +64,4 @@ public class CardboardBoxSerialization {
}
return contents;
}
public static String convert(String data, String target) {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
ItemStack[] contents = new ItemStack[dataInput.readInt()];
// Read the serialized inventory
for (int i = 0; i < contents.length; i++) {
contents[i] = (ItemStack) dataInput.readObject();
}
dataInput.close();
return Base64Coder.encodeLines(writeInventory(contents));
} catch (Exception e) {
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to convert vault " + target, e);
}
return null;
}
}