Skull Skins 1.14+

Discussion in 'Spigot Plugin Development' started by Splodgebox, Aug 15, 2019.

  1. Hello,
    For some reason, Minecraft versions 1.14+ the skin on player heads just come as a normal skull without a skin.
    Anything lower than 1.14 it works perfectly fine. Does anyone know why that is or if they changed anything in 1.14 to make this happen?

    Current code I am using:
    Code (Java):
    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;
    import lombok.experimental.UtilityClass;
    import org.apache.commons.codec.binary.Base64;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;

    import java.lang.reflect.Field;
    import java.util.UUID;

    @UtilityClass
    public class SkullUtil {

        private static Field profileField = null;

        public static ItemStack generateSkull(String owner) {
            ItemStack itemStack = XMaterial.PLAYER_HEAD.parseItem();
            SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
            skullMeta.setOwner(owner);
            itemStack.setItemMeta(skullMeta);
            return itemStack;
        }

        public static String getSkullURL(String skinURL) {
            byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", skinURL).getBytes());
            return new String(encodedData);
        }

        public static ItemStack getSkull(String skullUrl) {
            String base64Skin = skullUrl;
            ItemStack skull = XMaterial.PLAYER_HEAD.parseItem();

            ItemMeta skullMeta = skull.getItemMeta();
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            profile.getProperties().put("textures", new Property("textures", base64Skin));

            if (profileField == null) {
                try {
                    profileField = skullMeta.getClass().getDeclaredField("profile");
                } catch (NoSuchFieldException | SecurityException e) {
                    e.printStackTrace();
                }
                profileField.setAccessible(true);
            }

            try {
                profileField.set(skullMeta, profile);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                e.printStackTrace();
            }

            skull.setItemMeta(skullMeta);
            return skull;
        }
    }
     
  2. The generate skull method works fine for me in Spigot 1.14 (only switched the line where you get the ItemStack).
    I do not know about the other methods.

    Used this:
    Code (Java):

    public static ItemStack generateSkull(String owner) {
            ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD); // Edit here
            SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
            skullMeta.setOwner(owner); // This is depricated.
            itemStack.setItemMeta(skullMeta);
            return itemStack;
    }
     
  3. I mean that was the class im using but the method is the getSkull one
     
  4. Nope, have a closer look.

    Whilst you are using
    @CoolJWB is using
    This suggests that 'XMaterial' is returning incorrect data.
     
  5. Ah. You know what, that might actually be the issue.
     
  6. If that doesn't solve it try updating the skull state. That was my issue. Although I was having issues with a block, not an itemstack.
     
  7. Just tried the material thing but it seems that isn't the issue. Any ideas?
     
  8. I dunno what you are using as an IDE, or if you are building against spigot 1.14.4 ?
    But, when I paste your code into my IDE with the correct supporting libraries.
    There are library import errors (incorrect version) and 1 deprecation alert.
    (Without XMaterial included as @CoolJWB is using)
     
    #8 Goldentoenail, Aug 23, 2019
    Last edited: Aug 23, 2019
  9. Hmm perhaps your url?

    If ur using mcurl head thingy you'd do:
    http://textures.minecraft.net/texture/<mcurl>
     
  10. I tried that but for some reason, every other version is working fine but for 1.14 it's coming as a skeleton skull
     
  11. I'm using Intellij
    Gradle - Using 1.14.4 spigot API and server jar.
     
  12. Bump
    Can anyone help me?
     
  13. Okay if you look at my first message, there is my code.

    The issue is that all other versions get the skin for the skull but for some reason on 1.14 it comes as a normal skeleton skull instead of one with a skin.
    I've tried SkullCreator already, it doesn't work with this issue
     
  14. I just tried SkullCreator and was able to create a skin in 1.14.4.
    Code (Text):
    ItemStack itemStack = SkullCreator.itemFromUuid(givePlayer.getUniqueId());
    givePlayer.getInventory().addItem(itemStack);
     
     
  15. Im using Base64. My bad for forgetting to mention.
     
  16. What is the Base64? Does it have this format when decoded?
    Code (Text):
    {"textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/720420bbf80fd11a2f6f9638c5082d73bc64101039920737d2db083f6ea3c173"}}}
     
  17. That's the thing, the base64 value is fine because it works on 1.8-1.13 but it just breaks when used on 1.14
     
  18. Decode the Base64. Go on a website that lets you, and post an example here so I can see the difference.
     
  19. Code (Text):
    {"textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/6bb2e69b3870fe2f4f1ba14a8f9ca8acc9a7520e4e4a9784c19a3a0c9446e4d"}}}