what's the method player.updateInventory() used for?

Discussion in 'Spigot Plugin Development' started by HorrendousEntity, Jun 23, 2018.

  1. Nothing to extend beyond title.
     
  2. DavidDevelops

    Supporter

    did you look at the docs at all? I'm normally helpful and would explain but, the docs do it better...
    "
    Forces an update of the player's entire inventory.
    "
    is what it does, and if you don't know when to use it you don't need it, I don't think its used often if at all i have never seen someone use it or use it myself, I Don't know when we would need to force an update but i guess just in case...
    EDIT >> From what i find its useless as it autoupdates (as i thought) and WAS if not still deprecated ​
     
    • Optimistic Optimistic x 1
  3. Actually its usefull to use after cancelling a inventory interact event. In my experience not using it sometimes allowed users to shit click out item.
     
    • Useful Useful x 1
  4. Wow, brilliant explanation!
    I'm now knowledgeful of when to use this method and etc.
     
  5. DavidDevelops

    Supporter

    Really? Never seen a single GUI plugin use it a guess... used to be deprecated and Spigot/Bukkit auto updates inventories soo... Would you mind pming me and showing me when you would use this :D?
     
  6. can you explain your claim?
    Personally I saw this method being used a lot of times and I never understood what the word "update" means.. It sounds like a spigot-inner-stuff method
     
  7. DavidDevelops

    Supporter

    I'd love to help but what do you mean "explain what update means"? Update meaning if items changed in the inventory and for some reason it didn't auto update you could force it to show the new data,
     
  8. All I meant is for example..
    I never saw "updating bugs" in my game.
     
  9. It is used whenever a desync can/may happen. I've used it quite a few times, and seen it used in many plugins and situations. It's not as bad as it used to be, but inventory desync still occurs often enough to need this method. It's supposed to be a temporary workaround hacky fix, but its turning out to be more permanent as the years go on. It's even undeprecated in Spigot API (not Bukkit API). Its used many times in the server implementation itself because of Mojang bugs, desync issues with cancelled events, updating itemstack counts, etc etc.
     
  10. I'm totally confused by anything I heard about this method.
    Everyime for example I'm dealing with items & inventories I should use it?
     
  11. Thats a hard question to answer. It's a hacked together method, but it doesn't hurt anything to use it.

    CraftPlayer.java:
    [​IMG]
    EntityPlayer.java:
    [​IMG]

    As you can see all it does is send all items in the active inventory to the client, updates the item on the cursor (the item being dragged), and updates first item in any crafting slots if found (to force the client to recalculate the matrix result).

    If you are ever dealing with inventories and things dont work as expected it is generally resolved by doing an updateInventory() after you modified the inventory (or even 1 or 2 ticks afterwards) in most cases.