Create second player inventory [1.13.2]

Discussion in 'Plugin Development' started by JikaiNoTsubasa, Feb 11, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    JikaiNoTsubasa

    Hi,

    I'd like to create a second inventory for the player in order to extend the first one.
    I've found out that you can create one with Bukkit.createInventory but I have some questions about it.
    Here is a snippet:
    Code:
    Inventory inv = Bukkit.createInventory(player, InventoryType.PLAYER);
    player.openInventory(inv);
    My questions are:
    • How is the normal inventory (the classic one) stored between sessions? Is there a way to store the second one I just created or am I obliged to store it manually for all items inside through an external file?
    • Will it behave like a normal inventory, like it will fill up when I pick up items from floor or should I implement the listener to look if the classic inventory will be full and should add to the secondary?
    • I plan to open it when calling /inv, should I recreate it each time it's called and fill it with all items stored in the external file, or can I save it in the plugin with a kind of hashmap with the player as the key and call it?
    I'm trying to figure out if there are process behind the seen I can use instead of developing a lot in order to save time. Maybe some of you have a deeper view of how inventory are working. I'm trying to avoid re-creating the wheel but if I have to I'll do it..
    Thank you for your inputs.
     
  2. If you create a new inventory it will not be implemented in minecraft automatically. That means you have to save it on your own, open it manually whenever you want and place items manually in it. But once created you can put it in a hashmap and use it again.
     
  3. Offline

    JikaiNoTsubasa

    Hi DerDonut,

    thank you, I already started to implement it like this. And it works quite well.
    I just have a question on the difference of the following:
    Code:
    Inventory inv = Bukkit.createInventory(null, InventoryType.CHEST);
    Inventory inv = Bukkit.createInventory(player, InventoryType.CHEST);
    What does it implies to set it as null? Will it change the behavior?
     
  4. Well that's a good question. I always set it to null, so I'm pretty sure it will not effect the behavior of the inventory. I think it's useful to like sort the inventories and it might help you when checking if the current inventory is that specific inventory (for example in a listener). So you can for example check if the open inventory is from a chest or from a minecart, you dont have to compare the titles.
    You can also create your own type of inventory holder and then you are able to easily detect weather its opened or not
     
  5. Offline

    0-o

    The first parameter of Bukkit.createInventory() is just the owner of the inventory.
    So when you set it to null, it means that the inventory doesn't belong to anyone.


    Bukkit.createInventory(InventoryHolder owner,InventoryType type)
     
  6. Offline

    JikaiNoTsubasa

    Ok, as I open it with a HashMap, I always know from who it is. So I can set it to null as well...

    Another question regarding storage of the content of the inventories between two server restarts:
    For the moment I stored the ItemStacks as custom xml files in my plugin's folder. But I came accross some issues. I need to store a lot of info for each stack like: Enchants, Lore, names etc. So I have to setup the storage process manually for each elements.
    Minecraft stores the player's inventory itself, can we use an already coded way to store custom inventories? Do you know if there's a class to call to store inventories? This would save me so much time...
     
  7. This would be very great but as far as I know there is no way to do this.
     
  8. Offline

    0-o

    How are you generating the xml files?
     
Thread Status:
Not open for further replies.

Share This Page