org.bukkit.util.io.BukkitObjectInputStream Java Examples
The following examples show how to use
org.bukkit.util.io.BukkitObjectInputStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InventoryTypeAdapter.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
public static Inventory fromBase64(String data) { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt()); // Read the serialized inventory for (int i = 0; i < inventory.getSize(); i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); return inventory; } catch (Exception e) { } return null; }
Example #2
Source File: ItemSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
/** * Get an ItemStack from a JsonObject. * * @param data The Json to read. * @param format The data format being used. Refer to {@link PlayerSerializer#serialize(PWIPlayer)}. * @return The deserialized item stack. */ public ItemStack deserializeItem(JsonObject data, int format) { switch (format) { case 0: return getItem(data); case 1: case 2: try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data.get("item").getAsString())); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) { return (ItemStack) dataInput.readObject(); } catch (IOException | ClassNotFoundException ex) { ConsoleLogger.severe("Unable to deserialize an item:", ex); return new ItemStack(Material.AIR); } default: throw new IllegalArgumentException("Unknown data format '" + format + "'"); } }
Example #3
Source File: ItemSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
/** * Get an ItemStack from a JsonObject. * * @param data The Json to read. * @param format The data format being used. Refer to {@link PlayerSerializer#serialize(PWIPlayer)}. * @return The deserialized item stack. */ public ItemStack deserializeItem(JsonObject data, int format) { switch (format) { case 0: return getItem(data); case 1: case 2: try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data.get("item").getAsString())); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) { return (ItemStack) dataInput.readObject(); } catch (IOException | ClassNotFoundException ex) { ConsoleLogger.severe("Unable to deserialize an item:", ex); return new ItemStack(Material.AIR); } default: throw new IllegalArgumentException("Unknown data format '" + format + "'"); } }
Example #4
Source File: Base64Serialization.java From PlayerVaults with GNU General Public License v3.0 | 6 votes |
public static Inventory fromBase64(String data, String target) { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt()); // Read the serialized inventory for (int i = 0; i < inventory.getSize(); i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); PlayerVaults.debug("Read " + inventory.getSize() + " items"); return inventory; } catch (Exception e) { PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to load vault " + target, e); } return null; }
Example #5
Source File: Base64Serialize.java From ServerTutorial with MIT License | 6 votes |
public static Inventory fromBase64(String data) { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt()); // Read the serialized inventory for (int i = 0; i < inventory.getSize(); i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); return inventory; } catch (Exception e) { } return null; }
Example #6
Source File: Base64Serialize.java From ServerTutorial with MIT License | 6 votes |
/** * Gets an array of ItemStacks from Base64 string. * * <p /> * * Base off of {@link #fromBase64(String)}. * * @param data Base64 string to convert to ItemStack array. * @return ItemStack array created from the Base64 string. * @throws IOException */ public static ItemStack[] itemStackArrayFromBase64(String data) { 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 (IOException | ClassNotFoundException e) { } return null; }
Example #7
Source File: InventoryTypeAdapter.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
public static ItemStack[] StringToInventory(String data) throws IOException { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); ItemStack[] items = new ItemStack[dataInput.readInt()]; 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); } }
Example #8
Source File: InventorySerialization.java From helper with MIT License | 5 votes |
public static ItemStack decodeItemStack(byte[] buf) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(buf)) { try (BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) { return (ItemStack) dataInput.readObject(); } } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e); } }
Example #9
Source File: InventorySerialization.java From helper with MIT License | 5 votes |
public static ItemStack[] decodeItemStacks(byte[] buf) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(buf)) { try (BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) { ItemStack[] items = new ItemStack[dataInput.readInt()]; for (int i = 0; i < items.length; i++) { items[i] = (ItemStack) dataInput.readObject(); } return items; } } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e); } }
Example #10
Source File: InventorySerialization.java From helper with MIT License | 5 votes |
public static Inventory decodeInventory(byte[] buf, String title) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(buf)) { try (BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) { Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt(), title); for (int i = 0; i < inventory.getSize(); i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } return inventory; } } catch (ClassNotFoundException | IOException e) { throw new RuntimeException(e); } }