[YAML] Select specific configuration section in a list based on data inside it?

Discussion in 'Plugin Development' started by RastaLulz, Apr 3, 2014.

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

    RastaLulz

    Hello,

    I'm working on a plugin that will handle many generic things, such as teams, spawns, etc. based on a (YAML) config file. The issue I'm having is referencing a specific configuration section inside a list based on data within said list, for example, a teams name.

    Code:
    teams:
      - team: Players
        color: dark red
        max: 50
      - team: Spectators
        color: aqua
        max: 50
    As you can see, you can't use "getConfigurationSection" on a specific team, as it is a list, and not a "unique" key. So for example, I couldn't easily access the configuration section of just "Players".

    Obviously I could order the teams by their name (as the main key, as oppose to -), but I'd like to know if there's an way an easy way to reference a specific configuration section in a list based on the data inside it, as there's other config instances where I'd like to use this way.
     
  2. Offline

    se1by

    You could do it like this:
    Code:
    teams:
      players:
        color: dark read
        max: 50
      spectators:
        color: aqua
        max: 50
    And access it like this:
    Code:java
    1. for (String key : config.getConfigurationSection("teams").getKeys(false)) {
    2. if ("players".equalsIgnoreCase(key) {
    3. //Do your stuff
    4. } else if ("spectators".equalsIgnoreCase(key) {
    5. //Do other stuff here
    6. }
    7. }
     
Thread Status:
Not open for further replies.

Share This Page