Use a default config.yml or getConfig.addDefault

Discussion in 'Spigot Plugin Development' started by Skillere_V2, Oct 12, 2019.

  1. Should default settings be set

    1. in config.yml (present in .jar file) and then copied to plugins/my_plugin/config.yml?
    2. using getConfig.addDefault meaning that default settings, that are untouched don't appear in plugins/my_plugin/config.yml?
  2. use saveDefaultConfig() to save the file then use getConfig#set(path, value). Every setting has to appear in the config file itself.
    #2 robertlit, Oct 12, 2019
    Last edited: Oct 12, 2019
  3. The config is just a way of storing data, so yeah the default setting should be copied to the plugins/<plugin-name>/config.yml. Setting it can be done in different ways, the best way is to use a settings manager, it will allow you to create .yml files and read/write to them. And I don't know what getConfig.addDefault does but everything you put in there should appear in the file.
  4. Gadse

    Gadse Previously GummiBoat

    I prefer using getConfig#addDefault, since it allows to add on to your already existing config, without having the owner deleting it. The way you use it is

    getConfig#addDefault(path, value)

    Both ways are perfectly fine though. If you want comments in your config and do not plan to change it in the future, it's probably the easiest for you to provide it as-is. If you want comments and plan to update it, there are a few resources on this site that allow you to add comments while adding to configs. If you don't need comments and plan to update it, use the way described above.
  5. The problem is that this may not really work when there are some configs that cannot be set to something by default but can only be set explicitly