Solved FileWriter - Config loads after second(!) reload

Discussion in 'Spigot Plugin Help' started by Flash2Boom, May 24, 2016.

  1. Code (Text):
    Variables.configWriter = new FileWriter(Variables.configFile);

    Variables.configWriter.write("This is a test"+ "\n");

    Variables.configWriter.close();
    reloadConfig();


    @SuppressWarnings("deprecation")
        public static void reloadConfig() {  
            InputStream defConfigStream = Variables.plugin.getResource("config.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                Variables.configCfg.setDefaults(defConfig);
            }
        }

    The plugin creates the config the first time I reload it.

    BUT it's going to "load" the strings at the second reload...

    Does anyone has an idea why this happens?
     
    #1 Flash2Boom, May 24, 2016
    Last edited: May 24, 2016
    • Why are you abusing static; what type is 'Variables'?
    • I'd imagine it only loads data on reload because it you have the code to load the data inside your reloadConfig() method.
    • Don't indent code under a warning supression.
    • We need more code to help you, and more information too.
     
  2. I figured it out myself ;)
    It was a simple mistake by using the default config in my variables class

    If someone has the same problem - here is the solution:

    simply use a YamlConfiguration: YamlConfiguration.loadConfiguration(YourFile);
    and not: yourPlugin.getConfig();

    easy to go!