Solved Multiple ItemStacks in config

Discussion in 'Spigot Plugin Development' started by Nico12, Jan 31, 2020.

  1. Hi, I have a configuration file.
    Code (Text):

          ID: IRON_SWORD
          SLOT: 3
          AMOUNT: 3
          - Skere
          - Skere
          ID: IRON_HOE
          SLOT: 2
          AMOUNT: 3
          - '& aSkere'
         ID: IRON_HELMET
         SLOT: 1
         AMOUNT: 3
         - 'Your helmet'
    what I need is to go through 35 sections like that and that obviously give the player the corresponding item of each section, I just don't know how to do it, could you help me?
    Thanks in advance
  2. Just use FileConfiguration#getConfigurationSection(String), loop over each entry and then give the player the item.
  3. You could loop through all the numbers by first storing them in a list. You can get all entries via:
    Code (Java):
    config.getConfigurationSection(your path).getKeys(false);
    Then while looping through that, you can create an Itemstack, and set their respective properties.
    • Like Like x 1
    • Winner Winner x 1
  4. ItemStacks are serializable using Bukkit's configuration API. The formatting won't be the same, but you can greatly simplify serializing and deserializing ItemStacks with YamlConfiguration#getItemStack and YamlConfiguration#setItemStack.
  5. Thanks! Works