Solved Bukkit Config - Is it possible to have a list within a list?

Discussion in 'Plugin Development' started by ohtwo, Mar 28, 2013.

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

    ohtwo

    Using Bukkit's configuration API, is it possible for you to have a list within a list? For example:
    Code:
    - List 1
      - Sublist
      - Sublist
    - List 2
      - Sublist
     
  2. Offline

    Tirelessly

    You can use ConfigurationSection.getKeys to turn the big list into a set of keys, then loop through that and get all the lists
     
  3. Offline

    RingOfStorms

    for(i =0; i<5; i++)
    getConfig.getStringList("MyEntries.list"+i);

    in the config it would look like:

    Code:
    MyEntries:
      list0:
      - item1
      - item2
      - item3
      list1:
      - item1
      - item2
      list3 ... up to list 4
    
     
    ohtwo likes this.
  4. Offline

    ohtwo

    RingOfStorms
    Is 4 lists a limit, or is it just the case in your example?
     
  5. Offline

    RingOfStorms

    Just my example. And that is really just one way of doing it.
    I chose 4 because the for loop went from 0-4.
     
  6. Offline

    ohtwo

    Sounds good. Thank you!

    RingOfStorms

    Actually, is it possible to use the for-each loop on this? If it is, what type would each list entry be? :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    RingOfStorms likes this.
  7. Offline

    Tirelessly

     
  8. Offline

    Wolvereness Bukkit Team Member

    http://yaml.org/spec/1.0/
    A 'list' inside of a 'list' would be like this:
    Code:
    entry:
    -
      - config.getList("entry").get(0).get(0)
      - config.getList("entry").get(0).get(1)
    -
      - config.getList("entry").get(1).get(0)
      - config.getList("entry").get(1).get(1)
    
    But what I think you want is:
    Code:
    entries:
      SomeBlah:
      - config.getSection("entries").getList("SomeBlah").get(0)
      - config.getSection("entries").getList("SomeBlah").get(1)
      SomeOther:
      - config.getSection("entries").getList("SomeOther").get(0)
      - config.getSection("entries").getList("SomeOther").get(1)
    
    My first example would loop like this:
    Code:
    for (List<?> subList : (List<List<?>>) config.getList("entry"))
        for (Object object : subList) {
            // stuff;
        }
    }
    
    Whereas the second example would loop like this:
    Code:
    ConfigurationSection entries = config.getSection("entries")
    for (String key : entries.getKeys(false)) {
        for (Object object : entries.getList(key)) {
            // stuff;
        }
    }
    
     
  9. Offline

    ohtwo

    Tirelessly
    Sorry, I totally missed your post. Thank you.

    Wolvereness
    Thank you for your detailed post. Second code was what I needed.
     
Thread Status:
Not open for further replies.

Share This Page