[1.12.2] Custom Head showing up as a steve head in GUI.

Discussion in 'Spigot Plugin Development' started by mrcat125x, Oct 13, 2018.

  1. I recently started working on a GUI and I was adding a custom head to the GUI, but instead of the head I wanted it to be, it was a steve head.
    Code (Text):
    public static void openSkull(Player player)
        {
            Inventory inv = Bukkit.createInventory(null, 9,
            ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Skulls");
       
            ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
            SkullMeta headMeta = (SkullMeta) skull.getItemMeta();
            GameProfile profile = new GameProfile(UUID.fromString("b1020848-2e34-4e4f-9ad2-313015df329c"), "skin392230");
            profile.getProperties().put("textures", new Property("textures", "eyJ0aW1lc3RhbXAiOjE1Mzk0MDYxNDc1NDgsInByb2ZpbGVJZCI6ImIxMDIwODQ4MmUzNDRlNGY5YWQyMzEzMDE1ZGYzMjljIiwicHJvZmlsZU5hbWUiOiJtcmNhdDEyNSIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODEwZjc4ZDIzODUwNGRkN2UwNmE2N2MyMWM0MGJiYzczZjA5MjU0ZDMzMjJhOTY1NTZjNTU2ZDMyNmY4ZjdmYyJ9fX0=", "C7hbvVDT1l9ey1pWMLb91w9mH2mcUDm/s7fwrQhs2nHvLeISwsUByQ8tVeAEiU3XzKABrIEvmOhoXX983PMDKWNJLfnn1kAYkQHAmC3Vg4u96Ps2kuri8Uvp+LDqm6Xoi1+H62unsdedP3N7aQwzwBEuOduBGxSbED8swj58TE3gk0NwMkur7mNkU/G0tHHC/0clDKhEfxnltBoXnwDqrYzqfZqakb5jFDuGYODmkdokWaJQXbHeklL07bWV5ckMyW773JeUXzPYI53ox4fJLFZJxN0+Ja65+Nre6ki6OjmgfBTUsNfZckEpmV5rRoI32CTG9gN6HfzLY5WiGSG42NCRMCL3OAzqJY+lzPAfUfjbc/CT3TX37xaacBGw3Sk94vd7y64PyBzmSlpyAnCxm6/L53QQNqKYCPjRMHhSivYy2AvVATKeJTYDXDdawyMxxsEcIiqsIdYSynGBGbplcNVwsu/oijjKDhXGbmd4dKD2Tb8aijrWLAiTzlrvgAYr/ATDF3nrrgWbSCrDkzINMdoKUNhapMI1Tw1vNmdrJqVV4qD6DuTjX7XiIAQzAVGomudPx6XB4EMLzsvgC+sW8AkBOtoFyrYE/jHjXTNDCpMX7QgkLDILY00bYT9JiZHfGXufTMEBjhHCM/zY1FtscaOjJHG0n9JMo+tKiT89uKw="));
            skull.setItemMeta(headMeta);
            try
            {
                Field profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException ex) {
                ex.printStackTrace();
            }
         
            inv.setItem(8, skull);
       
            player.openInventory(inv);
        }
    Can someone help me?
    Thanks.
     
  2. First set the profile in the headmeta and then set the item meta in the skull
     
  3. Sorry, I'm kinda new to this whole thing. Would I do something like this?

    Change
    Code (Text):
    Field profileField = headMeta.getClass().getDeclaredField("profile");
    to
    Code (Text):
    Field profileField = headMeta.getClass().getDeclaredField("mrcat125");
    and then would I do something like changing
    Code (Text):
    SkullMeta headMeta = (SkullMeta) skull.getItemMeta();
    to
    Code (Text):
    ItemMeta headMeta = (ItemMeta) skull.getItemMeta();
    ?
     

  4. Code (Java):

          skull.setItemMeta(headMeta);
            try
            {
                Field profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException ex) {
                ex.printStackTrace();
            }
     
    You should use
    Code (Java):
    skull.setItemMeta(headMeta);
    after
    Code (Java):
    try {
                Field profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException ex) {
                ex.printStackTrace();
            }
    Not before.
     
  5. You set the profile after the item meta has been set as said in the first reply
     

Share This Page