Solved How do I get an Inventory (array) from a config?

Discussion in 'Spigot Plugin Help' started by CypDasHuhn, Jul 15, 2021.

  1. Im making a Kit plugin, where you can create kits. It looks at your Inventory, and saves it in a config
    Code (Text):
    Player target = (Player) event.getWhoClicked();
    ItemStack[] SavedInv = target.getInventory().getContents();

    FileConfiguration config = Main.getPlugin().getConfig();

    config.set("Kits.KitId"+[id]"+.Inventory", SavedInv)
    Main.getPlugin().saveConfig();
    Now there ist the problem, when i want to do something like this:
    Code (Text):
    ItemStack[] GetInv = ( //Here the code that takes the Inventory from the Config )
    target.getInventory().setContents(SavedInv)
    How can i do this, or am i doing something completely wrong?
     
    #1 CypDasHuhn, Jul 15, 2021
    Last edited: Jul 16, 2021
  2. I think this is wrong
    Code (Java):
    config.set("Kits.KitId"+[id]"+.Inventory", SavedInv)
    It should not be ?
    Code (Java):
    config.set("Kits.KitId"+[id]+".Inventory", SavedInv);
    What would the inventory saved in config look like? This makes it easier to help you get the inventory :oops:
     
  3. Kits:
    KitId1:
    Inventory:

    - ==: org.bukkit.inventory.ItemStack
    v: 2730
    type: ACACIA_BOAT
    - ==: org.bukkit.inventory.ItemStack
    v: 2730
    type: LEAD
    - ==: org.bukkit.inventory.ItemStack
    v: 2730
    type: HOPPER
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null
    - null

    a inv could look like this, and null is an empty slot obv.

    edit: the space's are weird on this one, so yeah
     
  4. upload_2021-7-15_22-41-23.png
     

    Attached Files:

  5. The configuration is somewhat strange, I can not understand it well
    Anyway, I leave you an example of how you could do it
    ItemStack[]
     
    • Like Like x 1
  6. thank you very much! :)