Help with Skull Owner

Discussion in 'Spigot Plugin Development' started by Swedz, Jun 7, 2016.

  1. I'm very aware this has been posted before, but none of the other answers work for me..

    I'm using this code:
    Code (Text):
    ItemStack item2 = API.createItem(new ItemStack(Material.SKULL_ITEM, 1), "┬žaProfile", new String[] {});
    item2.setDurability((short) 3);
    SkullMeta item2Meta = (SkullMeta) item2.getItemMeta();
    item2Meta.setOwner(player.getName());
    item2.setItemMeta(item2Meta);
    And I always get an Alex head.

    I'm not sure if the server has to be in online mode to do this, because mine is offline mode (so it can use Bungeecord)

    Thanks in advance!
     
  2. Code (Text):
    ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, 3);
    SkullMeta meta = item.getItemMeta();
    meta.setOwner(playerName);
    item.setItemMeta(meta);
     
    that should work.
     
  3. ItemStacks only have two arguments. Material and int.
     
  4. Nope, they can have 3. The last one might be a byte.
     
  5. Argument 3 must be a short. But setting the durability to a short works also.

    You must cast item.getItemMeta() as SkullMeta or else you can't set the owner.
    Code (Text):
    ItemStack item2 = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta meta = (SkullMeta) item2.getItemMeta();
    meta.setOwner(player.getName());
    meta.setDisplayName("┬žaProfile");
    item2.setItemMeta(meta);
    still gives me an alex head.
     
  6. Code (Text):

    public static void createDisplay(Material material, int amount, byte type, String skull, Inventory inv, int Slot, String name, String lore) {
            ItemStack item = new ItemStack(material, amount, type);
            SkullMeta meta = (SkullMeta) item.getItemMeta();
            meta.setDisplayName(name);
            meta.setOwner(skull);
            ArrayList<String> Lore = new ArrayList<String>();
            Lore.add(lore);
            meta.setLore(Lore);
            item.setItemMeta(meta);

            inv.setItem(Slot, item);
        }
     
    This is what I use.

    EDIT: This does work