plugin.yml, getting children of a property.

Discussion in 'Plugin Development' started by Cowboys1919, Jul 13, 2012.

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

    Cowboys1919

    I have a property called world.places that i want to contain many different names (chosen by the user) which then have more sub-properties. A little hard to illustrate with words so ill show some yml
    Code:
    world:
      places:
        Userdefinedstuff1:
          something: value
          somethingelse: value2
        Userdefinedstuff2:
          something: value
          somethingelse: value2
    So from my code i want to do something like this
    Code:
    for (String s : config.getChildrenOf("world.places"))
    {
        if (config.contains("world.places."+s+".Userdefinedstuff1"))
        //and so on
    Of course, config.getChildrenOf is a function I made up to represent what want to do.

    How can I achieve this functionality?
     
  2. config.getKeys(false)
     
  3. Offline

    Cowboys1919

    Considering no "world.places" was specified in that call, what keys is that going to return me?

    Aye, a search of config.getkeys on google revealed this post which shows I need to use config.getConfigurationSection("Blocks").getKeys(false);

    Actually, Im getting a null pointer exception from this line
    Code:
    for (String s : config.getConfigurationSection("world.places").getKeys(false))
    event though my config.yml looks like
    Code:
    player:
      foodDoesntGoDown: true
      customChat: false
    world:
      places:
        Something1:
        Something2:
    I resolved this, seems that you need to specify a value too or it doesn't detect it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. use an list if you dont whant values
     
  5. Offline

    Cowboys1919

    Well, I made it so it auto generates lots of sub-properties for each of the children of world.places so when I gave it a value of '' and ran it it replaced it with all the stuff i specified! Seems easy enough
     
Thread Status:
Not open for further replies.

Share This Page