How to load yaml files with the new lib?

Discussion in 'Plugin Development' started by Pasukaru, Oct 13, 2011.

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

    Pasukaru

    Title pretty much says everything, but here is what I tried without success:

    Code:java
    1. File file = new File(plugin.getDataFolder(), "config.yml");
    2. YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
    3. config.getString("root.asdf");

    getString() always returns null at this point, but if I do this:
    Code:java
    1. config.set("root.asdf", "something");
    2. config.save(file);

    It saves the file properly and as long as i don't reload the plugin
    Code:java
    1. config.getString("root.asdf");

    returns "something" as expected.

    Loading the file like this doesnt work either:
    Code:java
    1. YamlConfiguration config = new YamlConfiguration();
    2. config.load(file);
    as it does pretty much the same as the first example. (Checked the source.)

    So the thing I'm missing/doing wrong is loading the file.
    Anyone got an idea how to fix this?

    Thanks in advance. :)
     
  2. Offline

    Sagacious_Zed Bukkit Docs

  3. Offline

    Pasukaru

    so.. i have to add defaults for every single node before it gets loaded from the file? :confused:
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    No, you can still supply defaults in some of the get methods.
     
  5. Offline

    Pasukaru

    Yea well, those always return null...
    I don't know how to load the file ... if I add something and write the file it works, but how do I load it?
    All I need is something like the old
    config.load();
    But I can't find anything that works.
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    if you use getConfig, you don't need to load it, it is done for you.
     
  7. Offline

    Pasukaru

    And there's my problem, getConfig() only loads the "config.yml".
    But I'm using several config files for my plugin. (It would be impossible to manage everything in one file).

    Gonna take a look at the getConfig() source, maybe I'll find something there that helps me.
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    Oh....
    In that case you want to use YamlConfiguration.loadConfiguration(File)
     
  9. Offline

    Pasukaru

    *points to first post*
    Thats what I tried, and it didn't work. :eek:
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    But you did not have to do that for config.yml

    @Pasukaru

    By Chance are you trying to load paths deeper than two levels?
    If so you need to update to a newer bukkit build 945 and newer.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  11. Offline

    Pasukaru

    @Sagacious_Zed
    Yea, but it doesnt even read something like "global.checkForUpdates". :/

    [edit]
    I guess i'll just use the old configs until i find out how to use the new lib.
     
  12. Offline

    Sagacious_Zed Bukkit Docs

    Found a fix, which apparently why it worked for me, you need to have a updated craftbukkit build too.
     
Thread Status:
Not open for further replies.

Share This Page