Opening Inventory in HashMap

Discussion in 'Spigot Plugin Development' started by Stevie212, Apr 13, 2017.

  1. Is it possible to open an inventory In a hashmap. So for example I have this hashmap

    <Player,Inventory>

    Is it possible to open the inventory which is the value?
     
  2. NathanWolf

    Supporter

    Yes, just call Player.openInventory, passing in your Inventory to show it to a player.
     
  3. Wew thanks you saved me some time
     
  4. One more thing does the inventory get updated when something is put in it? And how do I add an item to the inventory?
     
  5. NathanWolf

    Supporter

    Yes, the inventory will be a "live" view of the one shown to the player, so if they add/remove/modify you will see the changes.

    Inventory.addItem will work as normal.
     
  6. So another question if another players has that inventory open and another puts items, does it automatically update?
     
  7. No, it shouldn't. There's an update() or updateInventory() method that you would probably need to use.
     

  8. Alright it's p.updateInventory(). So would I be able to edit the slots and the title in the hashmap?
     
  9. I think so. I never worked with updating a "shared" inventory so I can't guarentee.
     
  10. Yes.
     
    • Agree Agree x 1
  11. NathanWolf

    Supporter

    Agree, I don't think the other poster is correct there. The inventory will be shared, just like if you are invsee'ing another player's inventory, all players will see updates immediately.
     
  12. Alright thanks I'll test that out. But how do I set a title and slots number if it's in a HashMap?
     
  13. maldahleh

    Wiki Team

    Like you would with any other inventory? There is no difference if it is in a HashMap or not.
     
  14. NathanWolf

    Supporter

  15. Alright guys thanks so much
     
    • Friendly Friendly x 1