How to get a Custom Textured Player Head 1.15.2

Discussion in 'Spigot Help' started by LogicalDark, Feb 26, 2020.

  1. I havn't found or seen any guides or help threads on this, so that's why I'm posting this. This is the code I used back in 1.14 to get a custom textured player head.

    Code (Text):
    public static ItemStack getCustomPlayerHead(String textureString)
        {
            // Create a new skull item stack of a player head
            ItemStack skull = new ItemBuilder().setMat(Material.PLAYER_HEAD).setAmount(1).getItemStack();
         
            // Cast its item meta to a skull meta
            SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
         
            // Create a new fake game profile
            GameProfile profile = new GameProfile(UUID.randomUUID(),null);
         
            // Set the textures property to the texture desired
            profile.getProperties().put("textures",new Property("textures",textureString));
         
            // Reflection
            Field profileField = null;
         
            // Get the declared field
            try
            {
                profileField = skullMeta.getClass().getDeclaredField("profile");
            }
            catch(Exception e1)
            {
                Msg.printError("CustomPlayerHead: No such field / Security exception");
                VertexCore.handleException(e1);
            }
         
            // Set this field to be accessible
            profileField.setAccessible(true);
         
            // Set the skull meta data
            try
            {
                profileField.set(skullMeta,profile);
            }
            catch(Exception e1)
            {
                Msg.printError("CustomPlayerHead: Illegal arguments / Illegal access");
                VertexCore.handleException(e1);
            }
         
            // reset the skull meta to the item stack
            skull.setItemMeta(skullMeta);
         
            return skull;
        }
    However this no longer seems to work in 1.15.2 because I get a null pointer exception now.

    What is the new method for getting custom textured player heads now?

    Edit 1:
    So with some testing it seems I 'can' create a custom textured head using this but I can't actually test the head or I get a null pointer.

    If you use the code above to get the head, you can do:
    Code (Text):
    System.out.println(skull.getType());
    System.out.println(skull.getAmount());
     
    But as soon as I try to test the ItemStack itself it throws a null pointer
    Code (Text):
    System.out.println(skull);
     
    #1 LogicalDark, Feb 26, 2020
    Last edited: Feb 26, 2020
  2. I think you will find more willing help in the "Spigot Plugin Development" forum place. :)
     
  3. Alright
    (Staff member feel free to lock this)