config.yml keeps resetting?

Discussion in 'Plugin Development' started by xIntimidating, Oct 1, 2013.

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

    xIntimidating

    I've been working with some config files lately and every time I edit the config and reload the server, it seems to reset it back the the one I had.
     
  2. Offline

    rtainc

    Are they config files for plugins, your server, or your own plugin you are making? If it's the first one, we can't help with that on the Bukkit forums.
     
  3. Offline

    xIntimidating

    It's for my personal plugin that I am making.
    Code:java
    1. String tag = getConfig().getString("tag");
    2. player.sendMessage(tag);

    That's how I grab the config.
    This is how I get my config loaded.
    Code:java
    1. public void onEnable()
    2. {
    3. PluginDescriptionFile p = getDescription();
    4. this.logger.info(p.getName() + " v" + p.getVersion() + " was turned on.");
    5. getConfig().options().copyDefaults(true);
    6. saveConfig();
    7. }
    8.  
    9. public void onDisable()
    10. {
    11. PluginDescriptionFile p = getDescription();
    12. this.logger.info(p.getName() + " v" + p.getVersion() + " was shut off.");
    13. getConfig().options().copyDefaults(true);
    14. saveConfig();
    15. }
     
  4. Offline

    DAZ3DNDC0NFUS3D

    you should check to see if the file exists before copying defaults
     
  5. Offline

    xIntimidating

    It does, because the string still gets the info. When I use the command, I get a response back.
     
  6. Offline

    DAZ3DNDC0NFUS3D

    I mean on the onEnable
    something like this:
    Code:java
    1. if (!new File(getDataFolder(), "config.yml").exists()) {
    2. saveDefaultConfig();
    3. }
     
  7. Offline

    xIntimidating

    Still does not work. It's whenever I changed line in the config, it'll say the config has been changed and needs to reload back to the original.
     
  8. Offline

    DAZ3DNDC0NFUS3D

    try this?
    Code:
        public void onEnable()
        {
        PluginDescriptionFile p = getDescription();
        this.logger.info(p.getName() + " v" + p.getVersion() + " was turned on.");
        if(!new File(getDataFolder(), "config.yml").exists()) {
            saveDefaultConfig();
        }
        }
       
        public void onDisable()
        {
        PluginDescriptionFile p = getDescription();
        this.logger.info(p.getName() + " v" + p.getVersion() + " was shut off.");
        }
     
  9. Offline

    xIntimidating

    Ahh, thankyou. It works now.
     
Thread Status:
Not open for further replies.

Share This Page