Configuration Section?

Discussion in 'Plugin Development' started by bdubz4552, May 19, 2014.

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

    bdubz4552

    I am trying to use a for loop to pick out multiple objects in my config, which are all contained within one object. If that didn't make sense (I can't think of a better way to say it) Here's a sample of my config:
    Code:
    groups:
        group 1:
            someValue: true
            anotherValue: 42
        group 2:
            someValue: false
            anotherValue: 39
        group 3:
            someValue: true
            anotherValue: 90
    Based on the javadoc it appears that I should use getConfig().getConfigurationSection() to select the "groups:", then within that select the individual groups with some other method. Is this accurate?
     
  2. Offline

    blobic123

    I would presume that something like this could be used.
    Code:java
    1. Set <String> groups = getConfig().getConfigurationSection("groups").getKeys(true);
    2. for (String group : groups) {
    3. Set <String> values = getConfig().getConfigurationSection("groups." + group).getKeys(true);
    4. for (String value : values) {
    5. if (value == "someValue") {
    6. Boolean someValue = getConfig().getBoolean("groups." + group + "." + value + ".someValue");
    7. } else if (value == "anotherValue") {
    8. int anotherValue = getConfig().getInt("groups." + group + "." + value + ".anotherValue");
    9. }
    10. }
    11. }

    This could be used if you have several groups but don't know there names in which to fetch the data from inside.
     
Thread Status:
Not open for further replies.

Share This Page