Solved Registering 30+ inventories

Discussion in 'Spigot Plugin Development' started by Webmets, Jun 5, 2017.

  1. Hello, i'm currently working on a prison core. And for all the mine related staff, there is a gui where everything can be configured about the mine. Now I was wondering, should I try to set up a system with 1 inventory initialized in the onEnable, or is it safe to give every mine variable (a-z, and a few event mines. 30+ for sure) its own inventory. Recently I read something that having loads of inventories registered can cause memory leaks, but i'm not sure if that is true.
     
  2. TomTheDeveloper

    Supporter

    Depends on what's in the inventories. If there is all different stuff in them, then sure, go ahead and create 30+ inventories. If all are the same, just use one.
     
  3. Every inventory contains a few items to change settings (one to change the spawn location, one to change the selection, one to change the blocks inside the mine, one to rename and so on) so should I try to have 1 inventory, and make sure only 1 player can look in them at a time, and then save what mine he was editing (since you cant rename the inventory)?
     
  4. TomTheDeveloper

    Supporter

    Looks like every inventory can be different. What I would do is just create 1 inventory for every mine. Tracking for which mine the inventory is, can be done in multiple ways:
    • Location
    • Inventory name
    • ...
    About having multiple players having access 1 inventory at the same time, I would just track them and update the inventories if somebody changes a setting. This way a player can see immediatly if somebody is changing the mine settings.
     
  5. Alright, thanks for the help :)
     
  6. TomTheDeveloper

    Supporter

    Remember that this is not the best solution but it doesn't really matter since 30 inventories is almost nothing. Although, if you really want to implement the best solution and most configurable, I would go with an inventory pool. (Take one out if you need it, put it back if you don't and create a new one if there aren't enough in the pool. )

    But that's probably overkill here hehe.
     
  7. I know that it is solved, but just another solution for people that are comming by on this post: You can go and do it real fancy. You could use the Window Items packet (http://wiki.vg/Protocol#Window_Items) to send to the player what items he should have and when he sends a interact packet (any packet containing an interaction with the window information) you could just modify what would happen. Then you have only one (I think you need to reserve at least 1 id) inventories saved on your server and every client has only data from the inventory it needs. It is not that easy to implement, but I think it is even better then the inventory pool solution @TomTheDeveloper said. But I don't think it is really something you should do for 30 inventories. More something you could do if you have a very big server with lots of people online.
     
  8. TomTheDeveloper

    Supporter

    You caught me there :p
     
  9. There is nothing that can defeat packets, except if you are trying to get good accessibility. :D