Skull setting Id and Texture Values

Discussion in 'Plugin Development' started by thechrisanator, Apr 14, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    thechrisanator

    how can I give players player heads that have NBT data like this (have custom textures)
    upload_2019-4-14_4-4-8.png
     
  2. If you have this texture value, you can use the following code to get an ItemStack:
    Code:Java
    1. JsonParser parser = new JsonParser();
    2. JsonObject o = parser.parse(new String(Base64.decodeBase64(<the Value>))).getAsJsonObject();
    3. String skinUrl = o.get("textures").getAsJsonObject().get("SKIN").getAsJsonObject().get("url").getAsString();
    4. ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    5. SkullMeta headMeta = (SkullMeta) head.getItemMeta();
    6. GameProfile profile = new GameProfile(UUID.randomUUID(), null);
    7. byte[] encodedData = Base64.encodeBase64(("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes());
    8. profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
    9. Field profileField = null;
    10. try {
    11. profileField = headMeta.getClass().getDeclaredField("profile");
    12. profileField.setAccessible(true);
    13. profileField.set(headMeta, profile);
    14. } catch (Exception e) {
    15. e.printStackTrace();
    16. }
    17. head.setItemMeta(headMeta);


    I'm not sure where i found this but if i find it again I'll attach the source
    Hope this helps
     
Thread Status:
Not open for further replies.

Share This Page