Solved Player picks up item when inventory is full

Discussion in 'Plugin Development' started by LukeR, Jul 20, 2019.

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

    LukeR

    I don't know why, but my player is picking up items with a full inventory.

    Im using p.getInventory().addItem(ItemStack[]) to add the items to the player's inventory. That method returns a map containing the items the could not fit inside the inventory. So, I drop those items down at the player's feet, but he is still able to pick them up.

    And the thing is, if I fly and let the items fall down, when I later run over the items I can no longer pick it up.

    It would help me out a lot of anyone could find out why this is happening, because I have done so much debugging and I am clueless. Here's my code that gives the player the items:
    Code:
    Map<Integer, ItemStack> items = p.getInventory().addItem(kit.getItems().toArray(new ItemStack[0]));
    for (Entry<Integer, ItemStack> e : items.entrySet()) {
        p.getWorld().dropItemNaturally(p.getLocation().getBlock().getLocation().add(0, 2, 0), e.getValue());
    }
    Thanks in advance!
    - A Bukkit developer with help in need
     
  2. Offline

    CraftCreeper6

    @LukeR
    after you add the items to their inventory, update the inventory to let bukkit know that you intentionally edited it.

    If that doesn't work, then, are you adding additional items to the inventory? "Overflow" you might call it, if so, upon removal of an item, an ItemStack that initially couldn't be added will be added in it's place.
     
  3. Offline

    Kars

    Before you drop the items, do p.updateInventory();
     
  4. Offline

    LukeR

    I've already tried updating the player's inventory before giving the items: still doesn't work

    I have found the solution: it was because I was in creative. (…)

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

Share This Page