Config Help

Discussion in 'Plugin Development' started by Vidsify, Dec 12, 2014.

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

    Vidsify

    Hi

    I have made a config.yml file and I have called it. The problem it I have set it up to have comments in it however when I load the server, go into my plugins file, open it the comments aren't there. Any ideas why?

    upload_2014-12-12_19-58-10.png




    upload_2014-12-12_20-7-53.png

    The top bit is the only comments working
     
    Last edited: Dec 12, 2014
  2. @Vidsify Show us how you are creating/saving your config.
     
  3. Offline

    Gamesareme

    @Vidsify Well the most likely reason that that may be the case, is that you are not saving your config on start up and reload.
    Try adding this into you onEnable() and onDisable()
    Code:
            this.saveDefaultConfig();
    
    I almost forgot, this will not work if you just plonk it into your code and then run it. You will also have to delete your other config, the one in the plugins folder of your server. After that though, you should not need to delete it again.
     
    Last edited: Dec 12, 2014
  4. @Gamesareme No need to use all of them, for a file like that you only need saveDefaultConfig();
     
  5. Offline

    Gamesareme

    @bwfcwalshy I king if figured that, just about to change it. I grabbed it from a plugin where I was experimenting with the config, and did not remove them. Oops. :p
     
  6. Offline

    mythbusterma

    @Gamesareme

    You also don't need to save the default config when you disable the plugin....that doesn't make much sense.



    @Vidsify

    It is because SnakeYAML doesn't preserve comments that aren't at the top of a file, if you want to save comments to a file, copy the file into the directory yourself and then don't write to the config.
     
  7. Offline

    Vidsify

    @bwfcwalshy @mythbusterma
    My OnEnable Code

    Code:
     public FileConfiguration config;
    
      public void onEnable()
      {
        PluginDescriptionFile pdffile = getDescription();
        this.log.info("[" + pdffile.getName() + "] v" + pdffile.getVersion() + " has been enabled!");
        this.log.info("[" + pdffile.getName() + "] by Vidsify");
        getServer().getPluginManager().registerEvents(this, this);
        loadConfiguration();
     
        //AutoUpdater
        if (getConfig().getBoolean("AutoUpdate", true)) {
            Updater localUpdater = new Updater(this, 80039, getFile(), Updater.UpdateType.DEFAULT, true);
          } else {
            getLogger().info("NOT AUTO-UPDATING");
            }
     
        //Load Vault
        setupPermissions();
        setupEconomy();
        setupChat();
        getLogger().info("Linked to Vault!");
          }
     
  8. Offline

    mythbusterma

    @Vidsify

    All you need to put there is saveDefaultConfig(), unless you're trying to copy comments, in which case copy the file from the .jar.
     
  9. Offline

    Vidsify

    @mythbusterma I have set up the comments in my config.yml so do I just add saveDefaultConfig() to my onEnable()
     
  10. Offline

    mythbusterma

    @Vidsify

    I said, "if you don't want to copy comments, use saveDefaultConfig(), if you do, copy the file yourself."
     
  11. Offline

    Vidsify

Thread Status:
Not open for further replies.

Share This Page