Skull Skin 1.14-1.14.3

Discussion in 'Spigot Plugin Development' started by Splodgebox, Jul 14, 2019 at 12:43 PM.

  1. Hey,
    Okay so pretty much this is the current way my plugin adds skins on skulls.
    Code (Java):
        /**
         * Applies the base64 string to the ItemStack.
         *
         * @param item The ItemStack to put the base64 onto
         * @param base64 The base64 string containing the texture
         * @return The head with a custom texture
         */

        public static ItemStack itemWithBase64(ItemStack item, String base64) {
            notNull(item, "item");
            notNull(base64, "base64");

            UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode());
            return Bukkit.getUnsafe().modifyItemStack(item,
                    "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}"
            );
        }
    For some reason it doesn't work for 1.14-1.14.3, was there a change to the API?

    (This is the SkullCreator from Dean B)
     
  2. Use SkullMeta#setOwner or use reflections
     
  3. Does #setOwner work with skin ID?
     
  4. Reflection does, try to decode/debug the base 64 string, also the unsafe thing is marked as deprecated so possible just got removed
     
  5. Code (Text):
        private ItemStack getSkull(String url) {
            ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            if(url == null)return head;
            if(url.isEmpty())return head;
           
           
            SkullMeta headMeta = (SkullMeta) head.getItemMeta();
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
            profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
            Field profileField = null;
            try {
                profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
                e1.printStackTrace();
            }
            head.setItemMeta(headMeta);
            return head;
        }
     
    • Agree Agree x 1