Solved How to set CustomHead item Textures?

Discussion in 'Spigot Plugin Development' started by MissingPotato, Jul 26, 2021.

  1. Back in 1.16 I would do something along the lines of:
    Code (Java):
            ItemStack i = super.generateItem(p);

            if ( this.getMaterial().equals(Material.PLAYER_HEAD) ) {
                // Check if we should add a head texture to the menu item
                if ( this.headTexture != null ) {
                    // Get the skull meta
                   
                    SkullMeta m = (SkullMeta) i.getItemMeta();
                    // Generate a random game profile
                    GameProfile profile = new GameProfile(UUID.randomUUID(), "");
                    // Get the profile's properties and update the texture of the head
                    profile.getProperties().put("textures", new Property("textures", this.headTexture));
                    try {
                        assert m != null;
                        Field profileField = m.getClass().getField("profile");
                        profileField.setAccessible(true);
                        profileField.set(m, profile);
                    } catch ( Exception e ) {
                        new CustomException(e);
                    }

                    // Set the item meta
                    i.setItemMeta(m);
                }
            }

            return i;
    Does anyone have any idea how to do it in 1.17.x? I keep getting the error:
    java.lang.NoSuchFieldException: profile
     
  2. Well this is weird, 1.17 still has the "profile" field...
    What is the output of "System.out.println(m.getClass().getName());"?
     
    • Funny Funny x 1
  3. use getDeclaredField not getField "profile" is not public. getField can only find public Fields
     
    • Friendly Friendly x 1
  4. Thank you so much, it worked perfectly! You the man!