Added comments to default config

Discussion in 'Plugin Development' started by Synapz, Jun 27, 2015.

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

    Synapz

    I would like to set comments above values to explain what they do. For example,
    Code:
    # Message that gets sent out when a player gets warned. Tags: %PLAYER% %REASON% %SENDER%
    broadcast-message: '&6%PLAYER% has been warned by &c%SENDER% for &c%REASON%'
    The problem is, when I try and load the default config the comments are removed.

    Code I'm using:
    Code:
        public void init(WarningManager wm) {
            // Create a DataFolder is there isn't one already
            if (!wm.getDataFolder().exists()) {
                wm.getDataFolder().mkdir();
            }
           
            wFile = new File(wm.getDataFolder(), "warnings.yml");
            // Create the Warning File in case it is not there
            if (!wFile.exists()) {
                try {
                    wFile.createNewFile();
                }
                catch (IOException e) {
                    Messenger.getMessenger().message(Bukkit.getConsoleSender(), "Could not save warnings.yml");
                    e.printStackTrace();
                }
            }
           
            this.wm = wm;
            wm.saveDefaultConfig(); // <--- this is the exact point where I load the default config values  
           
            warnings = YamlConfiguration.loadConfiguration(wFile);
            config = wm.getConfig();
           
            // Load all values from the config into memory to be utilized by the plugin
            loadValues(config);
        }
    And in the onEnable() I call this init() method.
     
  2. Offline

    mine-care

  3. Offline

    Xerox262

    This will save the default config with comments, but they will most likely be deleted if you call saveConfig();

    Code:java
    1. saveResource("config.yml", false); //Just the config name and boolean of if it should overwrite the file if it already exists
     
    Synapz likes this.
  4. Offline

    Synapz

    Worked awesome! I just set the plugin to call that in the onEnable() and the comments loaded perfectly. I used to have a method that would saveConfig() and save other files, so in that method I used the saveResource and it kept saying it already exists. I tried typing true so it gets replaced but it would copy over all the changed values. So I removed it and it worked! Not saving it at all except on onEnable().

    Thanks a lot for pointing me in the right direction too! I read it and it helped explain the problem I was having.
     
    mine-care likes this.
  5. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page