Solved PlayerPickupItemEvent setting ItemMeta

Discussion in 'Plugin Development' started by CoderMusgrove, Jun 4, 2014.

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

    CoderMusgrove

    I'm currently working with a minigame plugin, and it has custom item meta for the items. I am adding the feature of picking up items, such as arrows. So in this process, I want the arrow to group with the stack in the player's current inventory, if they have one. So I find the item stack to compare to, and set the item meta accordingly:
    Code:
    for (int i = 0; i < k.getItems().size(); i++) {
        ItemStack indexItem = k.getItems().get(i);
        if (indexItem.getType().equals(item.getType())) {
            item.setItemMeta(indexItem.getItemMeta());
            e.getItem().setItemStack(item);
            // broadcasts the correct display name
            Bukkit.broadcastMessage(e.getItem().getItemStack().getItemMeta().getDisplayName());
            break;
        }
    }
    The item stack did broadcast the correct name that I wanted for the item, which was light aqua "Arrow", but when I pick up the item, the item meta is reset. Why is this happening?

    SOLVED! I fixed the issue by instead cloning the ItemStack indexItem, then setting the amount to one. At that time, I put it in the player's inventory and play the item pickup sound to imitate the pickup of an item.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
Thread Status:
Not open for further replies.

Share This Page