How to save config without losing comments?

Discussion in 'Spigot Plugin Development' started by Kyllian, May 26, 2017.

  1. Hey, i want to save things to the config without losing my comments.

    I tried making my own save method:

    Code (Text):
    public void saveTheConfig() {
            File configFile = new File(getDataFolder(), "config.yml");
            FileConfiguration file = YamlConfiguration.loadConfiguration(configFile);
            try {
            } catch (Exception exc) {
    Doens't work at all.

    Is there any other way to do this?
  2. saveDefaultConfig(); doesn't remove comments
  3. But that doesn't update the variable I set.

    Code (Text):
                        main.getConfig().set("State", true);
                        main.inMode = true;
                        main.timeLeft = main.getConfig().getInt("KickDelay");
  4. After you set it add Main.saveConfig();

    Also the saveDefaultConfig(); should be called in your onEnable()
  5. Yes that would work...
    for a plugin with a single config/ plugin using the default config

    but if you @kyllian.31777 only have one config, then use the default config and in onEnable and onDisable, put saveDefaultConfig()