public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) { GameProfile profile = new GameProfile(uuid, name); boolean cape = capeUrl != null && !capeUrl.isEmpty(); List<Object> args = new ArrayList<Object>(); args.add(System.currentTimeMillis()); args.add(UUIDTypeAdapter.fromUUID(uuid)); args.add(name); args.add(skinUrl); if (cape) { args.add(capeUrl); } profile.getProperties().put("textures", new Property("textures", Base64Coder.encodeString(String.format(cape ? JSON_CAPE : JSON_SKIN, args.toArray(new Object[args.size()]))))); return profile; }
public Node representData(Object data) { Tag tag = Tag.STR; Character style = null; String value = data.toString(); if (StreamReader.NON_PRINTABLE.matcher(value).find()) { tag = Tag.BINARY; char[] binary; try { binary = Base64Coder.encode(value.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new YAMLException(e); } value = String.valueOf(binary); style = '|'; } // if no other scalar style is explicitly set, use literal style for // multiline scalars if (defaultScalarStyle == null && MULTILINE_PATTERN.matcher(value).find()) { style = '|'; } return representScalar(tag, value, style); }
/** * Builds a GameProfile for the specified args * * @param name The name * @param skinUrl Url from the skin image * @param capeUrl Url from the cape image * @return A GameProfile built from the arguments * @see GameProfile */ public static GameProfile getProfile(String name, String skinUrl, String capeUrl) { UUID id = UUID.randomUUID(); GameProfile profile = new GameProfile(id, name); boolean cape = capeUrl != null && !capeUrl.isEmpty(); List<Object> args = new ArrayList<>(); args.add(System.currentTimeMillis()); args.add(UUIDTypeAdapter.fromUUID(id)); args.add(name); args.add(skinUrl); if (cape) args.add(capeUrl); profile.getProperties().clear(); profile.getProperties().put("textures", new Property("textures", Base64Coder.encodeString(String.format(cape ? JSON_CAPE : JSON_SKIN, args.toArray(new Object[args.size()]))))); return profile; }
/** * * A method to serialize an {@link ItemStack} array to Base64 String. * * <p /> * * Based off of {@link #toBase64(Inventory)}. * * @param items to turn into a Base64 String. * @return Base64 string of the items. * @throws IllegalStateException */ public static 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); } }
/** * A method to serialize an inventory to Base64 string. * * <p /> * * Special thanks to Comphenix in the Bukkit forums or also known * as aadnk on GitHub. * * <a href="https://gist.github.com/aadnk/8138186">Original Source</a> * * @param inventory to serialize * @return Base64 string of the provided inventory * @throws IllegalStateException */ public static String toBase64(Inventory inventory) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); dataOutput.writeInt(inventory.getSize()); for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
/** * * A method to get an {@link Inventory} from an encoded, Base64, string. * * <p /> * * Special thanks to Comphenix in the Bukkit forums or also known * as aadnk on GitHub. * * <a href="https://gist.github.com/aadnk/8138186">Original Source</a> * * @param data Base64 string of data containing an inventory. * @return Inventory created from the Base64 string. * @throws IOException */ public static Inventory fromBase64(String data) throws IOException { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt(),"Vault"); for (int i = 0; i < inventory.getSize(); i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); return inventory; } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } }
/** * 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) 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); } }
public static ItemStack getSkullFromURL(String url, String name) throws Exception { ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sm = (SkullMeta) skull.getItemMeta(); sm.setOwner("NacOJerk"); skull.setItemMeta(sm); url = Base64Coder.encodeString("{textures:{SKIN:{url:\"" + url + "\"}}}"); GameProfile gp = new GameProfile(UUID.randomUUID(), name); gp.getProperties().put("textures", new Property("textures", url)); Object isskull = asNMSCopy(skull); Object nbt = getNMS("NBTTagCompound").getConstructor().newInstance(); Method serialize = getNMS("GameProfileSerializer").getMethod( "serialize", getNMS("NBTTagCompound"), GameProfile.class); serialize.invoke(null, nbt, gp); Object nbtr = isskull.getClass().getMethod("getTag").invoke(isskull); nbtr.getClass().getMethod("set", String.class, getNMS("NBTBase")) .invoke(nbtr, "SkullOwner", nbt); isskull.getClass().getMethod("setTag", getNMS("NBTTagCompound")) .invoke(isskull, nbtr); skull = asBukkitCopy(isskull); return skull; }
/** * * @param items * @return A base64 encoded String * @throws IllegalStateException * * It encodes an {@link ItemStack} array to a base64 String */ public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); dataOutput.writeInt(items.length); for (int i = 0; i < items.length; i++) { dataOutput.writeObject(items[i]); } dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
public static 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()]; 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); } }
@Test public void test() throws Exception { File file = new File(FileUtils.getFile("").getAbsolutePath() + "/src/main/resources/ezyfox/config/handlers.properties"); List<Class<?>> classes = ClassFinder.find("com.tvd12.ezyfox.sfs2x.serverhandler"); StringBuilder builder = new StringBuilder(); for(Class<?> clazz : classes) { if(!Modifier.isAbstract(clazz.getModifiers()) && Modifier.isPublic(clazz.getModifiers()) && !Modifier.isStatic(clazz.getModifiers())) { ServerEventHandler handler = (ServerEventHandler) clazz.getDeclaredConstructor( BaseAppContext.class).newInstance(newAppContext()); System.out.println(handler.eventName() + "=" + clazz.getName()); if(!handler.eventName().equals(ServerEvent.SERVER_INITIALIZING) && !handler.eventName().equals(ServerEvent.ZONE_EXTENSION_DESTROY) && !handler.eventName().equals(ServerEvent.ROOM_EXTENSION_DESTROY) && !handler.eventName().equals(ServerEvent.ROOM_USER_DISCONNECT) && !handler.eventName().equals(ServerEvent.ROOM_USER_RECONNECT)) builder.append(handler.eventName() + "=" + clazz.getName()).append("\n"); } } FileUtils.write(file, Base64Coder.encodeString(builder.toString().trim())); }
public static 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); } }
public static 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); } }
/** * 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 + "'"); } }
public static String toBase64(Inventory inventory) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(inventory.getSize()); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
public static Inventory fromBase64(String data) throws IOException { 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 (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } }
/** * Serializes an inventory to a encoded string. * * @param inventory The inventory to serialize * @return serialized string */ public static String toString(Inventory inventory) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream dataOutput = new DataOutputStream(outputStream); NBTTagList itemList = new NBTTagList(); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { NBTTagCompound outputObject = new NBTTagCompound(); CraftItemStack craft = getCraftVersion(inventory.getItem(i)); // Convert the item stack to a NBT compound if (craft != null) CraftItemStack.asNMSCopy(craft).save(outputObject); itemList.add(outputObject); } // Now save the list writeNbt(itemList, dataOutput); // Serialize that array return Base64Coder.encodeLines(outputStream.toByteArray()); }
/** * Deserializes an inventory from a string * * @param data String to deserialize * @return Deserialized inventory */ public static Inventory fromString(String data) { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); NBTTagList itemList = (NBTTagList) readNbt(new DataInputStream(inputStream), 0); Inventory inventory = new CraftInventoryCustom(null, itemList.size()); for (int i = 0; i < itemList.size(); i++) { NBTTagCompound inputObject = itemList.get(i); if (!inputObject.isEmpty()) { inventory.setItem(i, CraftItemStack.asCraftMirror( net.minecraft.server.v1_7_R1.ItemStack.createStack(inputObject))); } } // Serialize that array return inventory; }
public static String toBase64(Inventory inventory) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(inventory.getSize()); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
/** * Transfer a inventory into a string * * @param inventory Inventory * @return String */ @Deprecated public static String inventoryToString(Inventory inventory) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(inventory.getSize()); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
/** * Transfer a string into an inventory * * @param data String * @return Inventory * @throws IOException Failed. */ @Deprecated public static Inventory stringToInventory(String data) throws IOException { 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 (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } }
/** * Serializes an inventory to a encoded string. * * @param inventory The inventory to serialize * @return serialized string */ public static String toString(Inventory inventory) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream dataOutput = new DataOutputStream(outputStream); NBTTagList itemList = new NBTTagList(); // Save every element in the list for(int i = 0; i < inventory.getSize(); i++) { NBTTagCompound outputObject = new NBTTagCompound(); CraftItemStack craft = getCraftVersion(inventory.getItem(i)); // Convert the item stack to a NBT compound if(craft != null) CraftItemStack.asNMSCopy(craft).save(outputObject); itemList.add(outputObject); } // Now save the list writeNbt(itemList, dataOutput); // Serialize that array return Base64Coder.encodeLines(outputStream.toByteArray()); }
/** * Deserializes an inventory from a string * * @param data String to deserialize * @return Deserialized inventory */ public static Inventory fromString(String data) { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); NBTTagList itemList = (NBTTagList)readNbt(new DataInputStream(inputStream), 0); Inventory inventory = new CraftInventoryCustom(null, itemList.size()); for(int i = 0; i < itemList.size(); i++) { NBTTagCompound inputObject = itemList.get(i); if(!inputObject.isEmpty()) inventory.setItem(i, CraftItemStack.asCraftMirror(net.minecraft.server.v1_7_R4.ItemStack.createStack(inputObject))); } // Serialize that array return inventory; }
public static String toBase64(Inventory inventory) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(inventory.getSize()); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Cannot into itemstacksz!", e); } }
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; }
/** * * A method to serialize an {@link ItemStack} array to Base64 String. * * <p> * * Based off of {@link #toBase64(Inventory)}. * * @param items to turn into a Base64 String. * @return Base64 string of the items. * @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed */ public static 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 (ItemStack item : items) { dataOutput.writeObject(item); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
/** * A method to serialize an inventory to Base64 string. * * <p> * * Special thanks to Comphenix in the Bukkit forums or also known * as aadnk on GitHub. <a href="https://gist.github.com/aadnk/8138186">Original Source</a> * * @param inventory to serialize * @return Base64 string of the provided inventory * @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed */ public static String toBase64(Inventory inventory) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); // Write the size of the inventory dataOutput.writeInt(inventory.getSize()); // Save every element in the list for (int i = 0; i < inventory.getSize(); i++) { dataOutput.writeObject(inventory.getItem(i)); } // Serialize that array dataOutput.close(); return Base64Coder.encodeLines(outputStream.toByteArray()); } catch (Exception e) { throw new IllegalStateException("Unable to save item stacks.", e); } }
/** * * A method to get an {@link Inventory} from an encoded, Base64, string. * * <p> * * Special thanks to Comphenix in the Bukkit forums or also known * as aadnk on GitHub. * * <a href="https://gist.github.com/aadnk/8138186">Original Source</a> * * @param data Base64 string of data containing an inventory. * @return Inventory created from the Base64 string. * @throws IOException if we were unable to parse the base64 string */ public static Inventory fromBase64(String data) throws IOException { if(data.isEmpty()) return Bukkit.getServer().createInventory(null, 0); try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); int size = dataInput.readInt(); Inventory inventory = Bukkit.getServer().createInventory(null, (int)Math.ceil((double)size / inventoryMultipule) * inventoryMultipule); // Read the serialized inventory for (int i = 0; i < size; i++) { inventory.setItem(i, (ItemStack) dataInput.readObject()); } dataInput.close(); inputStream.close(); return inventory; } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } }
/** * 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 if we was unable to parse the base64 string */ public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException { if(data.isEmpty()) return new ItemStack[] {}; 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); } }
@Override public Node representData(final Object data) { Tag tag = Tag.STR; Character style = null; String value = data.toString(); if (StreamReader.NON_PRINTABLE.matcher(value).find()) { tag = Tag.BINARY; char[] binary; try { binary = Base64Coder.encode(value.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new YAMLException(e); } value = String.valueOf(binary); style = '|'; } // if no other scalar style is explicitly set, use literal style for // multiline scalars if (defaultScalarStyle == null && MULTILINE_PATTERN.matcher(value).find()) { style = '|'; } return representScalar(tag, value, style); }
private static Optional<String> obtainSkinFromSkull(ItemMeta meta) { try { final Class<?> cls = createClass("org.bukkit.craftbukkit.VERSION.inventory.CraftMetaSkull"); final Object real = cls.cast(meta); final Field field = real.getClass().getDeclaredField("profile"); field.setAccessible(true); final GameProfile profile = (GameProfile) field.get(real); final Collection<Property> props = profile.getProperties().get("textures"); for (final Property property : props) { if (property.getName().equals("textures")) { final String text = Base64Coder.decodeString(property.getValue()); final StringBuilder s = new StringBuilder(); boolean start = false; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '"') { start = !start; } else if (start) { s.append(text.charAt(i)); } } return Optional.of(s.toString()); } } } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException | ClassNotFoundException e) { Bukkit.getLogger().log(Level.WARNING, "Failed to set url of itemstack.", e); } return Optional.empty(); }
/** * Reloads the content from the fileSystem */ @Override public void reload() { this.items.clear(); try { final Cipher decipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); decipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64Coder.decode("NTk50mqoZMw9ZTxcQJlVhA=="), "AES"), new IvParameterSpec("RandomInitVector".getBytes("UTF-8"))); try (BufferedReader reader = new BufferedReader(new InputStreamReader(new CipherInputStream(JavaPlugin.getPlugin(PetBlocksPlugin.class).getResource("minecraftheads.db"), decipher)))) { String s; final String splitter = Pattern.quote(","); int i = 0; while ((s = reader.readLine()) != null) { final String[] tags = s.split(splitter); if (tags.length == 2 && tags[1].length() % 4 == 0) { i++; try { final String line = Base64Coder.decodeString(tags[1]).replace("{\"textures\":{\"SKIN\":{\"url\":\"", ""); final String url = line.substring(0, line.indexOf("\"")); final String texture = url.substring(7, url.length()); final GUIItemContainer container = new ItemContainer(true, i, GUIPage.MINECRAFTHEADS_COSTUMES, 397, 3, texture, false, tags[0].replace("\"", ""), new String[0]); this.items.add(container); } catch (final Exception ignored) { PetBlocksPlugin.logger().log(Level.WARNING, "Failed parsing minecraftheads.com head.", ignored); } } } } } catch (IOException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) { PetBlocksPlugin.logger().log(Level.WARNING, "Failed to read minecraft-heads.com skins."); } }
@Override public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); if (profile.getId() != null) { result.add("uuid", context.serialize(profile.getId())); } if (profile.getName() != null) { result.addProperty("username", profile.getName()); } if (!profile.getProperties().isEmpty()) { result.add("properties", context.serialize(profile.getProperties())); } if (result.has("properties")) { JsonArray properties = result.getAsJsonArray("properties"); for (JsonElement entry : properties) { JsonObject property = (JsonObject) entry; String value = property.getAsJsonPrimitive("value").getAsString(); value = Base64Coder.decodeString(value); property.remove("value"); property.add("value", new JsonParser().parse(value)); } } return result; }