summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org
diff options
context:
space:
mode:
authorElgarL <ElgarL@palmergames.com>2012-08-19 14:49:16 +0100
committerElgarL <ElgarL@palmergames.com>2012-08-19 14:49:16 +0100
commit979da6e713ca7ac9300c7bed13584fae41de2d06 (patch)
treedc398fb0ded0a46bb69b42078553dee2e3ab0075 /EssentialsGroupManager/src/org
parent84f7859ca96ee475afe9544ce7ff9b69aee939e4 (diff)
downloadEssentials-979da6e713ca7ac9300c7bed13584fae41de2d06.tar
Essentials-979da6e713ca7ac9300c7bed13584fae41de2d06.tar.gz
Essentials-979da6e713ca7ac9300c7bed13584fae41de2d06.tar.lz
Essentials-979da6e713ca7ac9300c7bed13584fae41de2d06.tar.xz
Essentials-979da6e713ca7ac9300c7bed13584fae41de2d06.zip
No more null errors from corrupt config.yml's.
Diffstat (limited to 'EssentialsGroupManager/src/org')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java94
1 files changed, 65 insertions, 29 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
index fcc018d17..95fd35eb0 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
@@ -7,6 +7,7 @@ package org.anjocaido.groupmanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
@@ -21,10 +22,10 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
*/
public class GMConfiguration {
- private boolean opOverride;
- private boolean toggleValidate;
- private Integer saveInterval;
- private Integer backupDuration;
+ private boolean opOverride = true;
+ private boolean toggleValidate = true;
+ private Integer saveInterval = 10;
+ private Integer backupDuration = 24;
private String loggerLevel = "OFF";
private Map<String, Object> mirrorsMap;
@@ -35,6 +36,16 @@ public class GMConfiguration {
public GMConfiguration(GroupManager plugin) {
this.plugin = plugin;
+
+ /*
+ * Set defaults
+ */
+ opOverride = true;
+ toggleValidate = true;
+ saveInterval = 10;
+ backupDuration = 24;
+ loggerLevel = "OFF";
+
load();
}
@@ -44,14 +55,14 @@ public class GMConfiguration {
if (!plugin.getDataFolder().exists()) {
plugin.getDataFolder().mkdirs();
}
-
+
File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
try {
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
} catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
+ GroupManager.logger.log(Level.SEVERE, "Error creating a new config.yml", ex);
}
}
@@ -61,7 +72,7 @@ public class GMConfiguration {
FileInputStream configInputStream = new FileInputStream(configFile);
GMconfig = (Map<String, Object>) configYAML.load(new UnicodeReader(configInputStream));
configInputStream.close();
-
+
} catch (Exception ex) {
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
}
@@ -69,28 +80,53 @@ public class GMConfiguration {
/*
* Read our config settings ands store them for reading later.
*/
- Map<String, Object> config = getElement("config", getElement("settings", GMconfig));
-
- opOverride = (Boolean) config.get("opOverrides");
- toggleValidate = (Boolean) config.get("validate_toggle");
-
- /*
- * data node for save/backup timers.
- */
- Map<String, Object> save = getElement("save", getElement("data", getElement("settings", GMconfig)));
-
- saveInterval = (Integer) save.get("minutes");
- backupDuration = (Integer) save.get("hours");
-
- Object level = ((Map<String, String>) getElement("settings", GMconfig).get("logging")).get("level");
- if (level instanceof String)
- level = (String) level;
-
- /*
- * Store our mirrors map for parsing later.
- */
- mirrorsMap = (Map<String, Object>) ((Map<String, Object>) GMconfig.get("settings")).get("mirrors");
-
+ try {
+ Map<String, Object> config = getElement("config", getElement("settings", GMconfig));
+
+ opOverride = (Boolean) config.get("opOverrides");
+ toggleValidate = (Boolean) config.get("validate_toggle");
+
+ /*
+ * data node for save/backup timers.
+ */
+ try {
+ Map<String, Object> save = getElement("save", getElement("data", getElement("settings", GMconfig)));
+
+ try {
+ saveInterval = (Integer) save.get("minutes");
+ } catch (Exception ex) {
+ GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'minutes' node. Using default setting", ex);
+ }
+
+ try {
+ backupDuration = (Integer) save.get("hours");
+ } catch (Exception ex) {
+ GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'hours' node. Using default setting", ex);
+ }
+
+ } catch (Exception ex) {
+ GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'data' node. Using default settings", ex);
+ }
+
+
+
+ Object level = ((Map<String, String>) getElement("settings", GMconfig).get("logging")).get("level");
+ if (level instanceof String)
+ level = (String) level;
+
+ /*
+ * Store our mirrors map for parsing later.
+ */
+ mirrorsMap = (Map<String, Object>) ((Map<String, Object>) GMconfig.get("settings")).get("mirrors");
+
+ } catch (Exception ex) {
+ /*
+ * Flag the error and use defaults
+ */
+ GroupManager.logger.log(Level.SEVERE, "There are errors in your config.yml. Using default settings", ex);
+
+ mirrorsMap = new HashMap<String, Object>();
+ }
// Setup defaults
adjustLoggerLevel();
plugin.setValidateOnlinePlayer(isToggleValidate());