getStringList() not working on YML file

Discussion in 'Plugin Development' started by nuclearmissile, Aug 11, 2014.

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

    nuclearmissile

    This is an exact YML file that I have saved in my plugin's data folder:

    Code:
    Arenas:
      arena:
        t1spawns:
        - -525:72:-414
        t2spawns:
        - -520:73:-414
        t3spawns:
        - -523:72:-414
        t4spawns:
        - -525:72:-414
        t5spawns: []
        t6spawns: []
        t7spawns: []
        t8spawns: []
        dimension: 776395da-3f72-48fa-9ac2-d3dad761ad4d
    
    When I call getStringList("Arenas") it returns an empty string list. Why does it do that? And how can I make it so that it returns (in this particular case) a list with one member, that member being the string "arena" ?
     
  2. Offline

    Gerov

    @nuclearmissile That isn't a string list, if you wanted to get the list from say... t1spawns, you would do this,

    Code:java
    1. getConfig().getStringList("Arenas.arena.t1spawns");


    You separate each sub category with a "."

    :)
     
  3. Offline

    nuclearmissile

    I know that, I want to get all sub categories directly below "Arenas:"

    In this file, the only category directly below Arenas is "arena" but eventually there will be multiple.
     
  4. Offline

    nuclearmissile

  5. Offline

    Stealth2800

    Code:java
    1. ConfigurationSection sec = getConfig().getConfigurationSection("Arenas");
    2.  
    3. for (String arenaName : sec.getKeys(false)) {
    4. ConfigurationSection arenaSec = sec.getConfigurationSection(arenaName);
    5. // Do stuff. 'arenaSec' contains t1spawns, t2spawns, and so on.
    6. }
     
  6. Offline

    xTigerRebornx

    nuclearmissile Like he said, that isn't a StringList, it is a ConfigurationSection. You are able to get the keys of it using ConfigurationSection#getKeys(), getKeys(false) will exclude children keys, getKeys(true) will include children. I assume you only want the parents, so use getKeys(false)
     
Thread Status:
Not open for further replies.

Share This Page