Wiped config

Discussion in 'Plugin Development' started by HackintoshMan, Jul 18, 2013.

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


    After every reload, my config gets wiped. I cant figure it out and I know it will be something simple:mad:

    public void onEnable() {
        public void onDisable() {
        public void loadConfig() {
            if (new File("plugins/Plugin Name/").exists()) {
                System.out.println("Config is here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            } else {
                getConfig().set("Player Join Message", "");
                getConfig().set("Player Quit Message", "");
                getConfig().set("First Time Player Join Message", "");
                getConfig().set("Death.Ender Dragon Message", "");
                getConfig().set("Death.Blaze Message", "");
                getConfig().set("Death.Cave Spider Message", "");
                getConfig().set("Death.Creeper Message", "");
                getConfig().set("Death.Ghast Message", "");
                getConfig().set("Death.Magma Cube Message", "");
                getConfig().set("Death.Silverfish Message", "");
                getConfig().set("Death.Skeleton Message", "");
                getConfig().set("Death.Slime Message", "");
                getConfig().set("Death.Spider Message", "");
                getConfig().set("Death.Spider Jockey Message", "");
                getConfig().set("Death.Zombie Message", "");
                getConfig().set("Death.Enderman Message", "");
                getConfig().set("Death.Wolf Message", "");
                getConfig().set("Death.Zombie Pigman Message", "");
                getConfig().set("Death.Player Message", "");
                System.out.println("Config is NOT here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  2. Offline


    The config is always loaded into memory when the server starts. When it's loaded for the first time, the values will be set to their defaults. If you try to change the config, the changes will not be loaded into memory until you reload or restart the server (or manually call reloadConfig()). When saveConfig() is called, the values loaded into memory will be used, not the current values. Since you're calling this in your onDisable(), the config will be set to the default whenever you reload the plugin. There's actually no need to call the method in your onDisable(), or even in the onEnable(). Instead, you should create a default config.yml file and put it in the root directory of your Java project, then call saveDefaultConfig() in your onEnable(). If the config does not exists, the one present in your JAR will be written to disk. If it already does, nothing will happen. Only call saveConfig() when you absolutely need to.
  3. Offline


    Oh ok, let me try it.

    AngryNerd It worked, but now when I call values it always returns as null...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 3, 2016
  4. Offline


    Configs are case sensitive so make sure its correct.
    It also looks like its null because you set it to null with:
    getConfig().set("Death.Skeleton Message", "");
  5. Offline



    But I changed those values manually after I ran and restarted the server. Even when there was text it returned null.
  6. Offline


    replace the spaces between the path names with _, in your set and get method from the config! And replace the spaces in the config with _
Thread Status:
Not open for further replies.

Share This Page