Solved Converting ConfigurationSections into a string object?

Discussion in 'Plugin Development' started by jdawgerj515, Jul 27, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    jdawgerj515

    Hey guys, So I was wondering what the most effecient way of getting a list of sub-pathways of another high level sub-pathway was:

    Example:
    Code:
    world:
        country:
            state:
                  county:
            state:
    So lets say I wanted to get a list of the states from a country. If I try to use getStringList(world.country) It actually won't work. It will return nothing. The reason is because its children are also lists and not values.

    So I am asking what is the best way to do this.

    Is there a way to do something similar to getKeys(boolean) except with no boolean and only within "world.country" to get only a list of states?
     
  2. Offline

    Alex5657

    Code:java
    1.  
    2. ConfigurationSection section = config.getConfigurationSection("world.country");
    3. //You have all the paths to your states in this list
    4. List<String> paths = section.getKeys(true);
    5.  
     
    jdawgerj515 likes this.
  3. Offline

    rippin

    ninjad!
     
  4. Offline

    jdawgerj515

    Alex5657
    Oh wow... it is that easy?

    Lol thanks
     
  5. Offline

    Alex5657

    Yeah, sometimes I myself am surprised by the simplicity of the Bukkit API ;)
     
  6. Offline

    jdawgerj515

    Alex5657
    Ya I originally thought I was gonna have to get crafty with an Iterator to do this xD
     
  7. Offline

    soulofw0lf

    you can also use
    for (String key : config.getConfigurationSection("world.country").getKeys(false)){
    //code
    //example
    String county = config.getString("world.country." + key);
    stateCountyMap.put(key, county);
    }
    to iterate through it and use the value for something instead of assigning it to a list
     
Thread Status:
Not open for further replies.

Share This Page