Solved Trying to make a skull head the player's head

Discussion in 'Plugin Development' started by MayoDwarf, Oct 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    MayoDwarf

    Code:java
    1. ItemStack skull = new ItemStack(Material.SKULL, 1);
    2. SkullMeta skullMeta = skull.getItemMeta();
    3. skullMeta.setDisplayName("" + players.getName());
    4. skullMeta.setOwner("" + players.getName());
    5. skull.setItemMeta(skullMeta);
    skullMeta.getItemMeta() is highlighted and has errors. Why?
     
  2. MayoDwarf
    You are giving an ItemStack SkullMeta, and not ItemMeta.
     
  3. Offline

    MayoDwarf

    Then the setOwner is undefined...
     
  4. Offline

    Seadragon91

    You need to cast it. Change
    SkullMeta skullMeta = skull.getItemMeta();
    to
    SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
     
  5. MayoDwarf

    You can't set a ItemStack's meta to SkullMeta. You would have to define your itemstack as a skull.

    At least, I think that is what is going on.
     
  6. Offline

    MayoDwarf

    Still not working...

    Code:java
    1. ItemStack skull = new ItemStack(Material.SKULL, 1);
    2. SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
    3. skull.setDurability((short) 3);
    4. skullMeta.setDisplayName("" + players.getName());
    5. skullMeta.setOwner("" + players.getName());
    6. skull.setItemMeta(skullMeta);
    7.  
    8. skull.addUnsafeEnchantment(Enchantment.THORNS, 1);
    9. inv.addItem(skull);
     
  7. Offline

    Seadragon91

  8. Offline

    Retherz_

    make it SKULL_ITEM and why are you setting it owner and name to "" + players.getName() and not only players.getName()?

    edit:
    SkullMeta skulleMeta = (SkullMeta)skull.getItemMeta();
     
  9. Offline

    MayoDwarf

    I made it Skull_Item and now no more errors but the player head will not be their skin's head. Why?
     
  10. Offline

    Retherz_

    instead of using "" infront of their name

    skullMeta.setOwner(<playername>); try that instead of "" infront, because here is code is use:



    ItemStack skull = new ItemStack(Material.SKULL_ITEM);
    String headName = player.getName();
    skull.setDurability((short)3);
    SkullMeta sm = (SkullMeta)skull.getItemMeta();
    sm.setOwner(headName);

    List<String> lore = new ArrayList<String>();
    lore.add("§cSlain by " + killer.getName());
    sm.setLore(lore);
    skull.setItemMeta(sm);
     
  11. Offline

    MayoDwarf

    Still don't work bro xD :/ MercilessPvP

    MercilessPvP Seadragon91
    Maybe this will help:
    Code:java
    1. for(Player players : Bukkit.getOnlinePlayers()) {
    2. if(!players.getName().equals(p.getName())) {
    3.  
    4. String pl = players.getName();
    5. ItemStack skull = new ItemStack(Material.SKULL_ITEM);
    6. skull.setDurability((short)3);
    7. SkullMeta sm = (SkullMeta) skull.getItemMeta();
    8. sm.setOwner(pl);
    9. sm.setDisplayName(ChatColor.AQUA + "" + pl);
    10. skull.setItemMeta(sm);
    11. skull.addUnsafeEnchantment(Enchantment.THORNS, 1);
    12.  
    13. inv.addItem(skull); }
    14. }


    Yo why won't it work?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  12. Offline

    Retherz_

    No idea, it works fine for me... Do you get any error/ do u get the item at all?
     
  13. Offline

    Goblom

    Whats the difference between ItemMeta & SkullMeta
     
  14. Offline

    MayoDwarf

    No errors or anything. The item shows up in the inventory but as a regular steve head and not their skin's head... So weird lmao... Can anyone else figure this out? Thanks
     
  15. Offline

    Retherz_

    The skin only appears when you place it or wear it, have u tried placing/wearing it?
     
  16. Offline

    MayoDwarf

    Oh wait so you mean, it will not show their face in the player head? Only when you place it?

    MayoDwarf MercilessPvP

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  17. Offline

    Retherz_

    Yes, it appears as a default skin head, but after you place it or wear it it will appear as the skin of the owner
     
  18. SkullMeta extends ItemMeta and adds more things like setting the persons face on it.
     
  19. Offline

    MayoDwarf

    So there is no possible way for it to look like the player head just in the inventory right?
     
  20. Offline

    Retherz_

    Not that i know, probably possible with a client mod
     
  21. Offline

    MayoDwarf

  22. Offline

    xTrollxDudex

    They're the same thing except one deals with items and the other with skulls.
     
Thread Status:
Not open for further replies.

Share This Page