/** * Method to check if the configuration version are different. will set #configRequiresUpdate to * true if versions are different */ void updateNecessary() { if (configVer.equalsIgnoreCase(configCurrent)) { attackControlLogger.info("Config is up to date"); } else { attackControlLogger.warning("Config is not up to date!"); attackControlLogger.warning("Config File Version: " + configVer); attackControlLogger.warning("Internal Config Version: " + configCurrent); attackControlLogger.warning("It is suggested to update the config.yml!"); configRequiresUpdate = true; } }
/** Method to update the configuration if it is necessary. */ void updateConfig() { if (configRequiresUpdate) { configVer = configCurrent; if (writeConfig()) { attackControlLogger.info("Configuration was updated with new default values."); attackControlLogger.info("Please change them to your liking."); } else { attackControlLogger.warning("Configuration file could not be auto updated."); attackControlLogger.warning("Please rename " + configFile + " and try again."); } } }
/** * Method for writing the configuration file. First we write the standard configuration part, than * we write the custom configuration part via #writeCustomConfig() * * @return true if writing the config was successful * @see #writeCustomConfig(java.io.PrintWriter) */ public boolean writeConfig() { attackControlLogger.debug("creating config"); boolean success = false; try { PrintWriter stream; File folder = main.getDataFolder(); if (folder != null) { folder.mkdirs(); } PluginDescriptionFile pdfFile = main.getDescription(); stream = new PrintWriter(pluginPath + configFile); attackControlLogger.debug("starting contents"); // Let's write our config ;) stream.println( "# " + pdfFile.getName() + " " + pdfFile.getVersion() + " by " + pdfFile.getAuthors().toString()); stream.println("#"); stream.println("# Configuration File for module [" + MODULE_NAME + "]"); stream.println("#"); stream.println("# For detailed assistance please visit: " + mainConfig.getPluginSlug()); stream.println(); stream.println("# Configuration Version"); stream.println("configVer: \"" + configVer + "\""); stream.println(); // Getting the custom config information from the top of the class attackControlLogger.debug("going for customConfig"); writeCustomConfig(stream); stream.println(); stream.close(); success = true; } catch (FileNotFoundException e) { attackControlLogger.warning("Error saving the " + configFile + "."); } return success; }