Solved So.... Configuration Sections..

Discussion in 'Plugin Development' started by Pizza371, Oct 24, 2013.

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

    Pizza371

    Hi! I'm wondering how to get if a section of my configuration exists..
    so if I did this:
    yaml.set("lol.1", "hey");
    2.34 hours later..
    did this
    if(yaml.getConfigurationSection("lol.1") == null);;;;;;;;;;
    or yaml.get("lol.1") == null
    Although.. I don't see why there is getConfigurationSection when you can get a section like above, unles they are different, I need help! ;c
    would this actually work? I need this bad because there's no other way to detect how many sections my for loop put into my config :(
    Thank you!
     
  2. Offline

    1Rogue

    Try "yaml.getConfigurationSection("lol")", instead of getting a YAML leaf/end node.
     
  3. Offline

    metalhedd

    You can loop through the keys:

    Code:java
    1.  
    2. ConfigurationSection s = yaml.getConfigurationSection("lol");
    3. if (s == null) {
    4. s = yaml.createSection("lol");
    5. }
    6. for (String key: s.getKeys(false)) {
    7. getLogger().info("lol." + key + "=" + s.getString(key));
    8. }
    9.  
     
  4. Offline

    Pizza371

    1Rogue metalhedd
    Thanks for the help!
    I'm basically trying to save an array of Locations to a config, I'll show you example code (can't get real code not on computer :p) you might be able to help me better
    Code:java
    1. void saveLocsToFile() {
    2. File f = new File("/blah");
    3. yamlconfig = yaml; //legit :P
    4. Location[] l = new Location[ bunch, of, different, locations ];
    5. for(int i = 0; i < l.length; i++) {
    6. yaml.set("lol." + i + ".x", l[i].getBlockX()); //same with all other co-ords + world string
    7. }
    8. }[/i]

    And as you see it might be a problem retrieving the data since I don't know how big the Location file has got( this is in a save() method for Arenas)
    so I would need to loop through them when retrieving them, but I would need to know if when the int reaches 5, if 5 existed in the yaml file
     
  5. Offline

    metalhedd

    The code I pasted allows you to loop through them regardless of how many you have.
     
    Pizza371 likes this.
  6. Offline

    Pizza371

    metalhedd Ohhhhhhh I see, I've been wondering how to get those, sorry I don't know why I didn't acknowledge what you said in the post, haha.
    Thank alot!
     
Thread Status:
Not open for further replies.

Share This Page