My strange issues with ItemStack()

Discussion in 'Plugin Development' started by tyam, Mar 17, 2011.

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

    tyam

    I'm working on a /give plugin that is capable of inserting colored wool, different wood, cocoa beans,etc, into inventory. According to the javadoc, I need to make my command like this
    So I've done this,

    player.getInventory().addItem(
    new ItemStack(block, count, (short) 0, data));

    Now, I should say this. The code works. That is, it makes the blocks correctly, and puts them directly in the inventory. And it doesn't error.

    So, what's the problem? Well, the problem is that the items only appear in the inventory AFTER the user logs off and logs back in.

    I've used other plugins that put items directly into the inventory that do not have this problem, so I know it's not just something that has to happen. I've even looked at the code for a few of them to try to figure out what's going on. But I can't find any issue.

    So what's going on?
     
  2. Offline

    Edward Hand

    Try calling this after editing the inventory:
    Code:
    thePlayer.updateInventory()
     
  3. Offline

    tyam

    Oh, great! Thank you. This works perfectly. :]
     
Thread Status:
Not open for further replies.

Share This Page