public PropertyMap deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { PropertyMap result = new PropertyMap(); Iterator i$; Map.Entry<String, JsonElement> entry; if ((json instanceof JsonObject)) { JsonObject object = (JsonObject) json; for (i$ = object.entrySet().iterator(); i$.hasNext(); ) { entry = (Map.Entry) i$.next(); if ((entry.getValue() instanceof JsonArray)) { for (JsonElement element : (JsonArray) entry.getValue()) { result.put( entry.getKey(), new Property((String) entry.getKey(), element.getAsString())); } } } } else if ((json instanceof JsonArray)) { for (JsonElement element : (JsonArray) json) { if ((element instanceof JsonObject)) { JsonObject object = (JsonObject) element; String name = object.getAsJsonPrimitive("name").getAsString(); String value = object.getAsJsonPrimitive("value").getAsString(); if (object.has("signature")) { result.put( name, new Property(name, value, object.getAsJsonPrimitive("signature").getAsString())); } else { result.put(name, new Property(name, value)); } } } } return result; }
/** * Return a skull that has a custom texture specified by url. * * @param url skin url * @return itemstack */ public static ItemStack getCustomSkull(String url) { GameProfile profile = new GameProfile(UUID.randomUUID(), null); PropertyMap propertyMap = profile.getProperties(); if (propertyMap == null) { throw new IllegalStateException("Profile doesn't contain a property map"); } String encodedData = Base64.encodeBytes(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); propertyMap.put("textures", new Property("textures", encodedData)); ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); ItemMeta headMeta = head.getItemMeta(); Class<?> headMetaClass = headMeta.getClass(); Reflections.getField(headMetaClass, "profile", GameProfile.class).set(headMeta, profile); head.setItemMeta(headMeta); return head; }
public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) { PropertyMap properties = profile.getProperties(); if (pp.skin != null) { properties.put( ClientLauncher.SKIN_URL_PROPERTY, new Property(ClientLauncher.SKIN_URL_PROPERTY, pp.skin.url, "")); properties.put( ClientLauncher.SKIN_DIGEST_PROPERTY, new Property( ClientLauncher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), "")); } if (pp.cloak != null) { properties.put( ClientLauncher.CLOAK_URL_PROPERTY, new Property(ClientLauncher.CLOAK_URL_PROPERTY, pp.cloak.url, "")); properties.put( ClientLauncher.CLOAK_DIGEST_PROPERTY, new Property( ClientLauncher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), "")); } }
public JsonElement serialize( PropertyMap src, Type typeOfSrc, JsonSerializationContext context) { JsonArray result = new JsonArray(); for (Property property : src.values()) { JsonObject object = new JsonObject(); object.addProperty("name", property.getName()); object.addProperty("value", property.getValue()); if (property.hasSignature()) { object.addProperty("signature", property.getSignature()); } result.add(object); } return result; }