How to change a public inventory for one player

Discussion in 'Plugin Development' started by RoundStrider, Nov 3, 2021.

  1. Offline

    RoundStrider

    I'm trying to make a shop plugin in spigot. What I did so far is the sell menu, but that's when I found a big problem and I lost my hope. The way how I did it and I intended to do it was by making a Shop class which contains a public member of all the important inventories like Shop menu, sell menu, and buy menu. All those inventories were same to all players. ( they had null owner. ) What would happen was, when the player clicks on sell menu, the sellMenu Inventory opens for that player and then when the player clicks on an item in his inventory, It goes to a slot in the sellMenu inventory. But that's when I realized that, since the inventory is common to all players, it would change for all sellMenu viewers when one did it.

    Can anyone help me by saying the best way to do it? Is making separate inventories for all players efficient? I thought of that but I thought it would be a stupid idea!
    The next way I thought of was to make a function called openInventory(Player player) and inside that a new inventory gets created for that player. That would be a good idea, but then I don't know how to check that inventory in inventoryClickEvent listener, because the way I used to identify an inventory is by checking if the object was the reference of the same instance. I did it in that way instead of checking titles, because I want some of the Inventory titles in the shop to be the same?

    If you read the whole thing, the solution might be a simple one but, please help me!

    Thank you!
     
  2. Offline

    KarimAKL

    @RoundStrider Your solution is correct; you want a new inventory for every player.
     
  3. Offline

    RoundStrider

    oh thanks for the reply, I thought it was inneficient because each player had a separate inventories
     

Share This Page