Solved Need some help with YAML Configuration

Discussion in 'Plugin Development' started by aman207, Jul 5, 2013.

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

    aman207

    So I am trying to create a separate config file, and it works, except for when I want to set a value.

    Here is a part of my code:
    Code:java
    1. List<String>ranks = plugin.getConfig().getStringList("ranks".toLowerCase());
    2. ranks.add(args[1].toLowerCase());
    3. plugin.getConfig().set("ranks",ranks);
    4. plugin.getConfig().createSection(args[1].toLowerCase());
    5. plugin.getConfig().createSection(args[1].toLowerCase()+"-commands");
    6. List<String>commands=plugin.getConfig().getStringList(args[1].toLowerCase()+"-commands");
    7. commands.add("putCommandsHere");
    8. plugin.getConfig().set(args[1].toLowerCase()+"-commands",commands);
    9. plugin.getConfig().set(args[1].toLowerCase(), 0);
    10.  
    11. File forumConfig = new File(plugin.getDataFolder()+File.separator, "forumConfig.yml");
    12. FileConfiguration forum = null;
    13. forum=new YamlConfiguration();
    14. forum.createSection(args[1].toLowerCase()+"-group");
    15. forum.set(args[1].toLowerCase()+"-group", 0);
    16.  
    17. plugin.saveConfig();
    18. forum.save(forumConfig);


    So whatever was in forumConfig.yml is overwritten and replaced with args[1]-group: 0 and I want it to add to the yaml.

    I'm pretty sure I am missing something really basic here, but I can't figure it out.

    Just in case you were wondering, the command I am using is /donate add [rankName].

    Thanks!
     
  2. Offline

    Wingzzz

    Could you post your forumConfig.yml via pastie/pastebin? Is the file written before you've .set(...)? If you're meaning to copy out any information from a resource in your .jar, you must first create the file / save the file to your machine. Then from there load your configuration (as a YAML format considering that's what you're working with) then:
    Code:java
    1. configuration.set("node", value);
    2. configuration.save(yaml);
    3. // yaml is of type File
    4. // configuration is of type YamlConfiguration

    Not sure if there is information missing from the post so if there's anything else you could possibly show (perhaps full main class and the full class of what you've shown above), then maybe I could pin point the problem for ya ;)
     
  3. Offline

    aman207

    Wingzzz
    I am using addDeafault to generate my forumConfig.yml
    Here is what is looks like by default: http://pastebin.com/qTyusTfk

    When the command /donate add [rankName] is ran, is it supposed to add another field with -group at the end. I do something similar using .getConfig but I am add -commands to the end, and that works fine.

    I hope you won't mind using github to look at my code. I was having a hard time formatting it on pastebin and its a little bit to large anyways. (Pardon my formatting errors)
    So for my CommandListener class, lines 73 to 137 is where I am trying to set to forumConfig.yml. Specifically, lines 108-114 is where it is overwriting itself.

    Now I noticed that in my MainClass on lines 64-70, it correctly sets the forumConfig.yml without overwriting it. But I am using almost the exact same code in my CommandListener. This confuses me. I think I am missing something really obvious here....

    Thanks for your help!
     
  4. Offline

    aman207

    Bump

    I really need help with this :/

    I managed to fix it myself

    I needed to call forum.load before I saved it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. Offline

    Wingzzz

    Glad to hear! Sorry I wasn't able to respond, I was away from my computer.
     
  6. Offline

    aman207

    Thanks anyways!
     
Thread Status:
Not open for further replies.

Share This Page