Load inventory from file

Discussion in 'Spigot Plugin Development' started by OopsyPoopsy, May 7, 2017.

  1. Hello Spigot.

    I was wondering how to load inventory from a file? I don't know how to set it but the code I have to save the inventory is:

    Code (Java):

    kit.getData().set("nodebuff." + p.getUniqueId().toString(), p.getInventory().getContents());

                    kit.saveData();
     
    Now I just need to be able to load the saved inventory.
     
  2. First of all, that doesn't save the inventory. That only saves the pointer to the array of ItemStack
     
  3. Take a look at this:
    https://bukkit.org/threads/serialize-inventory-to-single-string-and-vice-versa.92094/
     
  4. Doesn´t matter if the Inventory is virtual or not. Just think about copying the inventorys from virtual to the real-inventory. You can work around that, and if you scroll a bit you also find a method that already has the armor-saving inside.

    //Edit: And even if that would not work, you see how the mechanic is called, so you could google a bit around this topic.