Refresh The Contents Of An External Inventory Someone Is Viewing?

Discussion in 'Plugin Development' started by SnowGears, Feb 1, 2013.

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

    SnowGears

    Lets say player A is viewing the contents of a chest. When I add items to the chest like this: Inventory.add(ItemStack), player A does not see this change. It is only when player A closes the chest and reopens it when they see the changes to the inventory.

    Is there a way to update the inventory or the inventoryView or something that can allow player A to see the changes take place in real-time? This is essential to my plugin.

    Thanks in advance!
     
  2. Offline

    RealDope

    I think once the chest is opened and the contents are retrieved from the server, it's handled client side (not 100% positive don't trust me :3) but you may be slipping into "packets-territory"
     
  3. Offline

    H2NCH2COOH

    I'm not sure, try player.updateInventory() ?
     
  4. Offline

    RealDope

    That would update the actual inventory of the player I think..
     
  5. Offline

    SnowGears

    I believe so. I am still not sure what to do and I am really bad with packets...

    Bump

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

    SnowGears

    Bump. Still really need help.
     
  7. Offline

    SergeantMajorME

    I believe when a chest is opened it creates an inventory. You need to add it to the inventory he's looking at.
     
  8. Offline

    SnowGears

    I do add it to the same inventory. The item change does not appear until the player closes the inventory and reopens it. I want to know how to refresh the inventory so the new item shows up without having to close and reopen
     
  9. Offline

    RealDope

    Maybe your best bet is to close it and then immediately reopen it? Might look a little trippy in game but it would get the job done :3
     
  10. Offline

    SnowGears

    The only problem is I need to refresh it every second or two.... :p
     
  11. Offline

    RealDope

    Flickering inventory it is then :D
     
  12. Offline

    SnowGears

    I guess so... that might be the only way to do it. I wish bukkit would add a method to refresh an inventory.... (hint hint bukkit team)
     
  13. Offline

    desht

    After you call inventory.add(...), get a list of the players currently observing that inventory view (inventory.getViewers()) and call player.updateInventory() on each of those observers.

    player.updateInventory() does indeed work for both parts of the inventory view, not just the player's own personal inventory; see the sortInventory() method from my ClickSort plugin here: https://github.com/desht/clicksort/.../me/desht/clicksort/ClickSortPlugin.java#L248
     
Thread Status:
Not open for further replies.

Share This Page