List of ConfigurationSections

Discussion in 'Plugin Development' started by MrTwiggy, Feb 26, 2013.

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


    Anyone know how to format a list of ConfigurationSections in a config.yml and subsequently how to get and loop through it? I would have figured it to be like this:

    - apple:
        color: red
        cost: 5.35
    - apple:
        color: green
        cost: 13.37
    - orange:
        color: purple
        cost: 0
    //In code to get the list
    ArrayList<ConfigurationSection> fruitSections = (ArrayList<ConfigurationSection>)getConfig().getList("fruits");
    However, it doesn't seem to work. I know I can just use 'fruitsConfigurationSection.getKeys(false)' and then iterate through the list, however, that would mean that each key 'apple, apple, orange' would need to be unique, which seems arbitrary and I'd like to avoid it if possible.
  2. Offline


    What do you want to do exactly? Maybe a YAML file is not the appropriate format for you. Describe your problem, and we may be able to help you.
  3. Offline


    I guess, you'll get back a list of maps so
    List<Map<String, Object>> fruitsSection = (List<Map<String, Object>>)getConfig().getList("fruits");
    each object value in the map can then also be a map itself.

    In this case each map will have one key: apple (for the first one). The value object will be a map containing two keys: color and cost with the appropriate data.
Thread Status:
Not open for further replies.

Share This Page