Solved Looping through config.

Discussion in 'Spigot Plugin Development' started by finnbon, May 24, 2016.

  1. Hello people!

    Maybe it is a stupid mistake from my side, but I'm trying to loop through my config to add arenas to the server.
    To do this, I use the following for-loop:
    Code (Java):
    for (String section : config.getConfigurationSection("").getKeys(false))
    The problem is that this does not seem to run at all. Is it not possible to loop through the first words in the config? My config has the following structure.
    Code (Text):

    ExampleArena:
      Name: TestArena
    Arena1:
      Name: AnArena
     
    Is there a different way I should be doing this?

    Thanks in advance.

    - Finn
     
  2. You could try this structure:

    Code (Text):
    Arenas:
      ExampleArena: TestArena
      Arena1: AnArena
     
    Code (Text):
    for (String section : config.getConfigurationSection("Arenas").getKeys(false))
    It's a bit more compact and will probably fit your needs a bit better.
     
  3. I have a .yml just for arenas. I know that structure will work for sure, just this seemed a little cleaner. Oh well :)
     
  4. Are you just storing the arena names in there? If so you could just store a list of the names under a key, would be even easier.
     
  5. Not just the names, just didn't feel like typing everything.
     
  6. Use Config.getKeys(false); ?
     
    • Agree Agree x 4
  7. @finnbon Every FileConfiguration instance is an instance of ConfigurationSection, so doing what @Vexentric said is what you need.
     
  8. Thanks for the solutions. :)
    Solved!
     
    • Like Like x 1