Solved Custom Skull Texture in GUI Menu

Discussion in 'Spigot Plugin Development' started by ChickenSaysBak, May 15, 2017.

  1. Hello, I've searched the ends of the google for how to do this but it's only showing how to get a custom head inside a player's inventory. I am trying to do this but instead, it would go into a GUI inventory menu.

    I already know how to do it with an existing player's skin like this: ItemName.setOwner("name");
    This is not what I am looking for, I need it to be a custom skin that does not update. (i.e. Using the base64 code).

    Help is appreciated! :)
     
  2. That's what I'm looking for, but it says to use:

    Code (Text):
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", this.playerSkullTexture).getBytes());
            profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
            Field profileField = null;
            try {
                profileField = im.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(im, profile);
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
                e1.printStackTrace();
            }
    Idk what "im" is, and also "playerSkullTexture" is underlined with the options to create field or create constant. Also another thing, a lot of the parts in that code require imports, but it lists tons of them and I'm not sure which ones I'm supposed to use lol
     
  3. Keep reading OP's post on that page where he explains his solution, OP tells you what 'im' is. If you are using a modern IDE, the IDE should handle which imports you need.
     
  4. Oh, I didn't see that part xD But what about the this.playerSkullTexture?
     
  5. Found it!

    Use this method:
    Code (Text):
        public static ItemStack getSkull(String url) {
            ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
            if(url.isEmpty())return item;
         
         
            SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
            profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
            Field profileField = null;
            try
            {
                profileField = itemMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(itemMeta, profile);
            }
            catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e)
            {
                e.printStackTrace();
            }
            item.setItemMeta(itemMeta);
            return item;
        }
    And then it can be used like so:
    ItemStack item = getSkull("http://textures.minecraft.net/texture/AllOfThatCrazyCodeStuffGoesHere");
     
    • Like Like x 1
    • Agree Agree x 1
    • Informative Informative x 1