Solved Giving player heads problems

Discussion in 'Plugin Development' started by MattexFilms, Aug 28, 2013.

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

    MattexFilms

    Here's what I'm trying to do: PlayerA uses a command which will give PlayerB the skull they are holding (if they are holding one that is).

    When this runs, PlayerB only gets a skeleton head and not the player head.

    Here's the code.

    Code:java
    1.  
    2. if(pl.getItemInHand().getType().equals(Material.SKULL_ITEM)){
    3. SkullMeta meta = (SkullMeta) pl.getItemInHand().getItemMeta();
    4. String owner = meta.getOwner();
    5.  
    6. ItemStack newSkull = new ItemStackMaterial.SKULL_ITEM);
    7. SkullMeta newSkullMeta = (SkullMeta) newSkull.getItemMeta();
    8. newSkullMeta.setOwner(owner);
    9. newSkull.setItemMeta(newSkullMeta);
    10.  
    11. pl.remove(pl.getItemInHand());
    12. tl.addItem(new ItemStack(newSkull));
    13. }


    Am I doing something completely wrong here?
     
  2. Offline

    fireblast709

    try
    Code:
    new ItemStack(Material.SKULL_ITEM, 3);
    (iirc 3 was the data for player heads)
     
  3. Offline

    MattexFilms

    I replaced this
    Code:java
    1. ItemStack newSkull = new ItemStackMaterial.SKULL_ITEM);

    With
    Code:java
    1. ItemStack newSkull = new ItemStackMaterial.SKULL_ITEM, 3);

    All that did was give 3 skeleton heads instead of 1.

    Just solved the problem.

    The item stack being given to PlayerB should have been this.

    Code:java
    1. ItemStack newSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());


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

    fireblast709

    lol my bad, forgot the order of parameters for the ItemStack constructor x3
     
Thread Status:
Not open for further replies.

Share This Page