Creating inventory with null InventoryHolder

Discussion in 'Spigot Plugin Development' started by i998979, Jan 6, 2020.

  1. So recently I'm dealing with custom gui, and I decided to create an abstract gui (not really abstract but, yea), and other guis extends that.
    Those gui has their own Inventory, ItemStack, Inventory events.

    After reading some tutorials and famous plugin''s source code, I've discovered that creating an inventory with non-null InventoryHolder isn't a good idea (https://www.spigotmc.org/threads/what-is-the-inventoryholder-interface.342812/)

    So what I'm going to ask are
    - Should I let my custom gui implements InventoryHolder?
    - Should I Bukkit#createInventory with InventoryHolder?
    - Is it possible to not putting InventoryHolder but still be able to compare gui looks like (just looks like)
    Code (Text):
    if (holder instnanceof MenuGUI)
    Also is there any plugin with good gui implementation that I can look into?

    Thanks

    Edit: Btw checking inventory's title seems not a good idea to determine which gui it is since it can be the same over different gui classes and it can be hard to check when the gui has dynamic name.
     
  2. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    I believe it is fair to create an inventory for each player and so the player becomes the owner. You can then retrieve the inventory from a HashMap. This also solves the issue to check the inventory based on the name.

    So when the inventory is called, check if inventory already exists, if it doesn't create a new inventory and add it to the HashMap
     
  3. Like this?

    Code (Text):

    HashMap<UUID, Inventory> playerInv = new HashMap<>();
    ... When the player is clicking inventory
    Retrieve inventory from HashMap
    ... I am running out of brain cells, whats next?
     
     
  4. The best thing to do here is to make a database with gui content defined by some value, can be player UUID or some other identification.