How to create ItemStack that is player skull but with custom skin from "value"?

Discussion in 'Spigot Plugin Development' started by Msql, Jan 9, 2020.

  1. How to create ItemStack that is player skull but with custom skin from "value"?
    I was searching for it, found few tutorials but they seem to be outdated.
    I have tried also this code:
    Code (Java):
    public static ItemStack getCustomTexturedHead(String value) {
       ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
       SkullMeta meta = (SkullMeta) head.getItemMeta();
       GameProfile profile = new GameProfile(UUID.randomUUID(), "");
       profile.getProperties().put("textures", new Property("textures", value));
       Field profileField = null;
       try {
          profileField = meta.getClass().getDeclaredField("profile");
          profileField.setAccessible(true);
          profileField.set(meta, profile);
       } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
          e.printStackTrace();
       }
       head.setItemMeta(meta);
       return head;
    }
    But it always return null.
    Thanks for any help!
     
    • Winner Winner x 1
  2. Seems to look fine. What are you inputting into value? What is giving an error? What line?
     
  3. There is no error. ItemStack return is always "null". I am using 1.15.1 newest spigot build, maybe they changed something?
    My value that I am testing is:
    Code (Text):
    eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjBhZmE0ZmZmZDEwODYzZTc2YzY5OGRhMmM5YzllNzk5YmNmOWFiOWFhMzdkODMxMjg4MTczNDIyNWQzY2EifX19
    I have tried also with this code, but exactly same result:
    Code (Java):
    public static ItemStack getCustomTexturedHead(String value) {
       net.minecraft.server.v1_15_R1.ItemStack item = CraftItemStack.asNMSCopy(new ItemStack(Material.PLAYER_HEAD, 1));
       NBTTagCompound tag;
       if (item.hasTag()) {
          tag = item.getTag();
       } else {
          tag = new NBTTagCompound();
       }
       NBTTagCompound skullOwner = new NBTTagCompound();
       NBTTagCompound properties = new NBTTagCompound();
       NBTTagList textures = new NBTTagList();
       NBTTagCompound texture = new NBTTagCompound();
       texture.setString("Value", value);
       textures.add(texture);
       properties.set("textures", textures);
       skullOwner.set("Properties", properties);
       tag.set("SkullOwner", skullOwner);
       item.setTag(tag);
       return CraftItemStack.asBukkitCopy(item);
    }
     
  4. Nevermind, it was my fault. First code just works perfectly.
     
    • Agree Agree x 1