Most performant way to create Inventories

Discussion in 'Spigot Plugin Development' started by ExoBiTe, Aug 29, 2019.

  1. Hey guys, i´ve got more of a design question for you:

    The Situation:
    Every Player has a "Profile" which contains stats. Other Players can look at their own Profile as well as they can look at other Players Profiles. These Profiles are represented by Inventories. These Inventories/Profiles could vary, as for the first it should show the selected Players stats (by setting the Items Lore/Name), as well as the Items Material.
    Also these Inventories could vary per "Viewer", as an Admin for example has some Buttons in the Profile too, which normal Players aren´t able to see/use.

    Now to my question:
    How would you do this?
    My two Ideas are now:
    1. Create one Inventory for every Player online at the Server, and modify/fill/clear it whenever its needed
    OR
    2. Use NMS and send Packets with InventoryViews whenever a Player opens a "Profile" and listen vor the clicked Slots (the Slots will always be the same).

    I am not sure how many Performance it will drag, if i create an Inventory and cache it all the Time for every Player with for example 100 Players online.

    Thanks for your advice :)
     
  2. Just create the inventory on request, check permissions and add items appropriately.

    Don’t worry about performance, this is hardly any work at all as long as you’re not being dumb. (Don’t grab stats from a databae, don’t create world’s, etc.)