save "defaults" (in my workspace) custom "config"

Discussion in 'Spigot Plugin Development' started by Yazio, Jun 29, 2015.

  1. hey i have tried to make a custom "config" ... but i wan't to know how i would save the strings and comments i have in my workspace (like when u make a default config and there is something inside it (saveDefaultConfig();))

    (sorry for my bad english)
     
  2. Easiest way to keep all the comments is just to save the file yourself via a writer or FileOutputStream. You can get the configuration file by doing something like MyPluginClass.class.getResource( "config.yml" );
     
  3. wat? (can u give me a hint how?)
     
    • Optimistic Optimistic x 1
  4. Code (Text):
    // Get resource "yml"

      InputStream readConfig = this.main.getResource(name);

            YamlConfiguration setDefaults = new YamlConfiguration().loadConfiguration(readConfig);

    // Set default config

       if(!this.file.exists()){
                    this.config.addDefaults(setDefaults);
                    this.config.options().copyDefaults(true);
                    this.config.save(this.file);
                }
     
    • Useful Useful x 1
  5. thanks ill try that