mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-21 10:52:01 +00:00
No more null errors from corrupt config.yml's.
This commit is contained in:
parent
84f7859ca9
commit
979da6e713
|
@ -193,4 +193,5 @@ v 2.0:
|
||||||
- Fix a cases sensitivity bug in world loading.
|
- Fix a cases sensitivity bug in world loading.
|
||||||
- Stop using the YamlConfiguration in bukkit for our config handling. We can now support periods in world names.
|
- Stop using the YamlConfiguration in bukkit for our config handling. We can now support periods in world names.
|
||||||
- Fix GlobalGroups not loading permission nodes.
|
- Fix GlobalGroups not loading permission nodes.
|
||||||
- Fix an error with Logging set to 'OFF' triggering a cast exception.
|
- Fix an error with Logging set to 'OFF' triggering a cast exception.
|
||||||
|
- No more null errors from corrupt config.yml's.
|
|
@ -7,6 +7,7 @@ package org.anjocaido.groupmanager;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -21,10 +22,10 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
|
||||||
*/
|
*/
|
||||||
public class GMConfiguration {
|
public class GMConfiguration {
|
||||||
|
|
||||||
private boolean opOverride;
|
private boolean opOverride = true;
|
||||||
private boolean toggleValidate;
|
private boolean toggleValidate = true;
|
||||||
private Integer saveInterval;
|
private Integer saveInterval = 10;
|
||||||
private Integer backupDuration;
|
private Integer backupDuration = 24;
|
||||||
private String loggerLevel = "OFF";
|
private String loggerLevel = "OFF";
|
||||||
private Map<String, Object> mirrorsMap;
|
private Map<String, Object> mirrorsMap;
|
||||||
|
|
||||||
|
@ -35,6 +36,16 @@ public class GMConfiguration {
|
||||||
public GMConfiguration(GroupManager plugin) {
|
public GMConfiguration(GroupManager plugin) {
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set defaults
|
||||||
|
*/
|
||||||
|
opOverride = true;
|
||||||
|
toggleValidate = true;
|
||||||
|
saveInterval = 10;
|
||||||
|
backupDuration = 24;
|
||||||
|
loggerLevel = "OFF";
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,14 +55,14 @@ public class GMConfiguration {
|
||||||
if (!plugin.getDataFolder().exists()) {
|
if (!plugin.getDataFolder().exists()) {
|
||||||
plugin.getDataFolder().mkdirs();
|
plugin.getDataFolder().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
try {
|
try {
|
||||||
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
|
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
|
||||||
} catch (IOException ex) {
|
} 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);
|
FileInputStream configInputStream = new FileInputStream(configFile);
|
||||||
GMconfig = (Map<String, Object>) configYAML.load(new UnicodeReader(configInputStream));
|
GMconfig = (Map<String, Object>) configYAML.load(new UnicodeReader(configInputStream));
|
||||||
configInputStream.close();
|
configInputStream.close();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), 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.
|
* Read our config settings ands store them for reading later.
|
||||||
*/
|
*/
|
||||||
Map<String, Object> config = getElement("config", getElement("settings", GMconfig));
|
try {
|
||||||
|
Map<String, Object> config = getElement("config", getElement("settings", GMconfig));
|
||||||
opOverride = (Boolean) config.get("opOverrides");
|
|
||||||
toggleValidate = (Boolean) config.get("validate_toggle");
|
opOverride = (Boolean) config.get("opOverrides");
|
||||||
|
toggleValidate = (Boolean) config.get("validate_toggle");
|
||||||
/*
|
|
||||||
* data node for save/backup timers.
|
/*
|
||||||
*/
|
* data node for save/backup timers.
|
||||||
Map<String, Object> save = getElement("save", getElement("data", getElement("settings", GMconfig)));
|
*/
|
||||||
|
try {
|
||||||
saveInterval = (Integer) save.get("minutes");
|
Map<String, Object> save = getElement("save", getElement("data", getElement("settings", GMconfig)));
|
||||||
backupDuration = (Integer) save.get("hours");
|
|
||||||
|
try {
|
||||||
Object level = ((Map<String, String>) getElement("settings", GMconfig).get("logging")).get("level");
|
saveInterval = (Integer) save.get("minutes");
|
||||||
if (level instanceof String)
|
} catch (Exception ex) {
|
||||||
level = (String) level;
|
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'minutes' node. Using default setting", ex);
|
||||||
|
}
|
||||||
/*
|
|
||||||
* Store our mirrors map for parsing later.
|
try {
|
||||||
*/
|
backupDuration = (Integer) save.get("hours");
|
||||||
mirrorsMap = (Map<String, Object>) ((Map<String, Object>) GMconfig.get("settings")).get("mirrors");
|
} 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
|
// Setup defaults
|
||||||
adjustLoggerLevel();
|
adjustLoggerLevel();
|
||||||
plugin.setValidateOnlinePlayer(isToggleValidate());
|
plugin.setValidateOnlinePlayer(isToggleValidate());
|
||||||
|
|
Loading…
Reference in a new issue