Solved Loop in config to store data to array from int

Discussion in 'Spigot Plugin Development' started by Ohwnead, Aug 16, 2018.

  1. Hi, i try to loop in my config to get multiple int like so :
    Code (Text):
      Stats:
        HP: 0
        StatsPoint: 0
        Terre: 0
        Feu: 0
        Air: 0
        Eau: 0
        DommagePhysique: 0
        DommageMagique: 0
        ResistanceMagique: 0
        ResistancePhysique: 0
    and to store them in an int[] with a for boucle (to return them)

    But my problem is the following : I don't know how i could loop on the "Stats" path :s to get children int.

    Thanks for help :3
     
  2. You could loop over the keys of the "Stats" ConfigurationSection. It would go like this...
    Code (Text):
    ConfigurationSection section = getConfig().getConfigurationSection("Stats");
    for (String key: section.getKeys(false)) {
        int value = section.getInt(key);
        // do something with value
    }
     
    • Like Like x 1
  3. Thanks a lot, it was perfectly what i want to use :D
    Solved
     
    • Like Like x 1