Second Config File doens't work :(

Discussion in 'Plugin Development' started by ImAFlo, May 31, 2015.

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

    ImAFlo

    My second config file doens't worked.
    The file get created, but the file stays empty.

    I debugged and I know, it executes all of the code, but the file stays empty! Plz Help :(

    Code:
     
    public void dbconf() {
    File dbfile = new File(getDataFolder(), "db.yml");
    FileConfiguration db = new YamlConfiguration();
    
    if(!dbfile.exists()){
    try {
    dbfile.createNewFile();
    } catch (IOException e) {
    e.printStackTrace();
    }
    try {
    db.load(dbfile);
    } catch (IOException | InvalidConfigurationException e1) {
    e1.printStackTrace();
    }
    this.reloadConfig();
    db.options().header("This is a DB file for saving informations from the plugin. DONT EDIT!");
    db.addDefault("General.spawnworld", null);
    db.addDefault("General.spawncorx", null);
    db.addDefault("General.spawncory", null);
    db.addDefault("General.spawncorz", null);
    db.options().copyDefaults(true);
    this.saveConfig();
    } else {
    }
    }
    
    Thanks in Advance
     
  2. Offline

    Dudemister1999

    @ImAFlo
    Not too sure about this, but try changing db to an instance of YamlConfiguration, and running this for loading instead of .load()

    Code:
    db = YamlConfiguration.loadConfiguration(dbFile);
    So your total changes should be:
    Code:
    YamlConfiguration db = new YamlConfiguration;
    
    db = YamlConfiguration.loadConfiguration(dbFile);
    Try that out, and see if it works.
     
  3. Offline

    teej107

    I don't think it's any different for defaults but setting a path value to null removes it.
     
Thread Status:
Not open for further replies.

Share This Page