diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java index f9ad11e2..a7fac2dd 100644 --- a/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java @@ -14,7 +14,7 @@ public class RoyalAuthYamlReader extends CustomConfiguration { * @param file File */ public RoyalAuthYamlReader(File file) { - super(file); + super(file, true); load(); save(); } diff --git a/src/main/java/fr/xephi/authme/hooks/EssSpawn.java b/src/main/java/fr/xephi/authme/hooks/EssSpawn.java index 0644ee10..95d516e8 100644 --- a/src/main/java/fr/xephi/authme/hooks/EssSpawn.java +++ b/src/main/java/fr/xephi/authme/hooks/EssSpawn.java @@ -13,7 +13,7 @@ public class EssSpawn extends CustomConfiguration { private static EssSpawn spawn; public EssSpawn() { - super(new File("." + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "spawn.yml")); + super(new File("." + File.separator + "plugins" + File.separator + "Essentials" + File.separator + "spawn.yml"), true); spawn = this; load(); } diff --git a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java index cb1719cb..f5d59e51 100644 --- a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java @@ -12,36 +12,70 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; -/** - */ public abstract class CustomConfiguration extends YamlConfiguration { + /** + * The file of the configuration. + */ private final File configFile; /** - * Constructor for CustomConfiguration. + * Constructor. + * This loads the configuration file. * - * @param file the config file + * @param file The file of the configuration. */ public CustomConfiguration(File file) { - this.configFile = file; - load(); + this(file, true); } + /** + * Constructor. + * + * @param file The file of the configuration. + * @param load True to load the configuration file. + */ + public CustomConfiguration(File file, boolean load) { + // Set the configuration file + this.configFile = file; + + // Load the configuration file + if(load) + load(); + } + + /** + * Load the configuration. + */ public void load() { + // Try to load the configuration, catch exceptions try { + // Load the configuration super.load(configFile); + } catch (FileNotFoundException e) { + // Show an error message ConsoleLogger.showError("Could not find " + configFile.getName() + ", creating new one..."); - reLoad(); + + // Reload the configuration and create a new file + reload(); + } catch (IOException e) { + // Show an error message ConsoleLogger.showError("Could not load " + configFile.getName()); + } catch (InvalidConfigurationException e) { + // Show an error message ConsoleLogger.showError(configFile.getName() + " is no valid configuration file"); } } - public boolean reLoad() { + /** + * Reload the configuration. + * + * @return + */ + public boolean reload() { boolean out = true; if (!configFile.exists()) { out = loadResource(configFile); @@ -51,14 +85,27 @@ public abstract class CustomConfiguration extends YamlConfiguration { return out; } + /** + * Save the configuration. + */ public void save() { + // Try to save the configuration, catch exceptions try { + // Save the configuration super.save(configFile); + } catch (IOException ex) { + // Show an error message ConsoleLogger.showError("Could not save config to " + configFile.getName()); } } + /** + * Get the configuration file. + * + * @return File. + */ + public File getConfigFile() { return configFile; } diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java index 32a5192b..9b443d6c 100644 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -19,7 +19,7 @@ public class Messages extends CustomConfiguration { * @param lang the code of the language to use */ public Messages(File file, String lang) { - super(file); + super(file, true); load(); singleton = this; this.lang = lang; diff --git a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java index 063e6af6..9058376f 100644 --- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java +++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java @@ -17,7 +17,7 @@ public class OtherAccounts extends CustomConfiguration { private static OtherAccounts others = null; public OtherAccounts() { - super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "otheraccounts.yml")); + super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "otheraccounts.yml"), true); others = this; load(); save(); diff --git a/src/main/java/fr/xephi/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java index 4c20b296..51c6b2d9 100644 --- a/src/main/java/fr/xephi/authme/settings/Spawn.java +++ b/src/main/java/fr/xephi/authme/settings/Spawn.java @@ -14,7 +14,7 @@ public class Spawn extends CustomConfiguration { private static Spawn spawn; public Spawn() { - super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "spawn.yml")); + super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "spawn.yml"), true); spawn = this; load(); save();