Solved Generating a Config

Discussion in 'Plugin Development' started by Chr0mosom3, Mar 19, 2019.

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

    Chr0mosom3

    I have been working on a plugin and I have created defaults,
    Code:
    getConfig().addDefault("Join", "&3% has joined the game");
    getConfig().addDefault("Leave", "&3% has left the game");
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
    saveConfig();
    But if there is no config.yml plugin then it returns an error on line 25, aka
    Code:
    saveDefaultConfig();
    I know that the problem is that there is no config.yml, but how do I create it then? Is there a way to generate a config?
     
  2. Offline

    KarimAKL

    @MrDaniel 'saveDefaultConfig()' should create it, not sure if you have to have the file in your project though. (I always have it in my project when using 'saveDefaultConfig()' and it works for me)
    Otherwise i think you could do something like this:
    Code:Java
    1. File file = new File(getDataFolder()+File.separator+"config.yml");
    2. file.createNewFile(); // Pretty sure this line needs a try catch
     
  3. Offline

    Chr0mosom3

    Fixed it myself, swapped saveConfig(); and saveDefaultConfig(); and it worked.
     
  4. Offline

    KarimAKL

    @MrDaniel I see, remember to mark as "Solved". :p
     
  5. Offline

    Chr0mosom3

    @KarimAKL, oh yea, sry, xD.I am usually the one who does that .-.
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page