Write Defaults to YAML File

Discussion in 'Plugin Development' started by McStormify, Apr 9, 2013.

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

    McStormify

    I know that it's possible to set the defaults with myConfig.setDefaults(whatever); but how does one write them to the .yml file? My code:

    Code:java
    1. folder = new File("plugins/MyPlugin/");
    2. file = new File(folder, "playerdata.yml");
    3.  
    4. playerData = new YamlConfiguration();
    5.  
    6. if (folder.exists() == false) {
    7. try {
    8. folder.mkdir();
    9. } catch (Exception e) {}
    10. }
    11.  
    12. if (file.exists() == false) {
    13. try {
    14. file.createNewFile();
    15. } catch (Exception e) {}
    16. }
    17.  
    18. try {
    19. playerData.load(file);
    20. } catch (Exception e) {}
     
  2. Offline

    NoLiver92

    wouldnt it be saveConfig() or saveDefaultConfig()?
     
  3. Offline

    Faith

    config.setDefault("message","this is a message");

    Not on my comp so I'm not sure.
     
  4. Offline

    McStormify

    I don't think so. I'm not using a config file, I'm using a YML file.

    Tried that, but it just sets it as default. It doesn't write it to the file.
     
  5. Offline

    McStormify

  6. You can just .set() the values and save the file if that's what you want.
    Or I belive you can use .addDefault() then .options().copyDefaults(true) and save...

    See what suits you best.
     
  7. Offline

    McStormify

    Exactly what I was looking for! Diamonds for you! [diamond]
     
  8. Offline

    gomeow

    You should use File.separator rather than a /
     
    McStormify likes this.
  9. McStormify
    Oh yeah and use plugin.getDataFolder() instead of manually defining the folder.
     
    McStormify likes this.
Thread Status:
Not open for further replies.

Share This Page