Solved addItem() ItemStack vanishes

Discussion in 'Plugin Development' started by Zethariel, May 14, 2014.

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

    Zethariel

    Hello!

    The most peculiar bug happened to me - while using the addItem() method, the given item vanished after right clicking. The item is being given from a hashmap - it's a book, and even more weird is the fact that when used, it does open the book edit GUI, but the book vanishes.

    It does not, however, vanish when I first move it around in the inventory - like place it in another slot or something. Then it behaves like normally.

    I've seen replies to similar topics stating that I need to specify a quantity, but the HashMap is being populated from a YML file - those itemstacks are easily obtainable from there (I tested by giving player direct access to an inventory created from the HashMap contents) and addItem() does not accept anything other than an ItemStack.

    Anyone has any clue what needs be done to stop this?
     
  2. Offline

    desht

    Check that the size of the item stack you've added (as returned by ItemStack#getAmount()) is greater than 0.
     
    Zethariel likes this.
  3. Offline

    Zethariel

    desht It is indeed 0. But how does that make sense? How can I create an ItemStack, store it, and have it of 0 quantity?

    EDIT: I get the ItemStack with ItemStack.deserialize(config.getConfigurationSection(key).getValues(false)). How would I make it to be 1 item?

    EDIT2: Okay, nevermind. It seems that for some reason Bukkit decided to serialize that particular item with an amount of 0. Wow. What the heck. Solved.
     
Thread Status:
Not open for further replies.

Share This Page