package de.softwarerat.modutils.Commands; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.io.BukkitObjectInputStream; import org.bukkit.util.io.BukkitObjectOutputStream; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class InvSeeCommand { public void Command(Player player , Player targetPlayer){ String CachedInvModerating = itemStackArrayToBase64(player.getInventory().getContents()); String CachedInvTarget = itemStackArrayToBase64(targetPlayer.getInventory().getContents()); } public ItemStack[] itemStackArrayFromBase64(String data) throws IOException { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); ItemStack[] items = new ItemStack[dataInput.readInt()]; // Read the serialized inventory for (int i = 0; i < items.length; i++) { items[i] = (ItemStack) dataInput.readObject(); } dataInput.close(); return items; } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } } public String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(items.length); // Save every element in the list for (int i = 0; i < items.length; i++) { dataOutput.writeObject(items[i]); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } } }