diff options
author | ElgarL <ElgarL@palmergames.com> | 2012-08-03 10:36:26 +0100 |
---|---|---|
committer | ElgarL <ElgarL@palmergames.com> | 2012-08-03 10:36:26 +0100 |
commit | 7b482b612e42a24bd2602a2c1a3dba15c146bc83 (patch) | |
tree | 6f12b032a516a2c3ddbb7b69db14dbd22b68233a /EssentialsGroupManager/src/org/anjocaido/groupmanager | |
parent | 6064b9760b9649d370fc41f407b80ddad331efba (diff) | |
download | Essentials-7b482b612e42a24bd2602a2c1a3dba15c146bc83.tar Essentials-7b482b612e42a24bd2602a2c1a3dba15c146bc83.tar.gz Essentials-7b482b612e42a24bd2602a2c1a3dba15c146bc83.tar.lz Essentials-7b482b612e42a24bd2602a2c1a3dba15c146bc83.tar.xz Essentials-7b482b612e42a24bd2602a2c1a3dba15c146bc83.zip |
Stop using the YamlConfiguration in bukkit for our config handling. We
can now support periods in world names.
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java | 95 |
1 files changed, 71 insertions, 24 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java index 0832000f2..34b50825a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java @@ -5,22 +5,32 @@ package org.anjocaido.groupmanager; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.util.Map; import java.util.logging.Level; import org.anjocaido.groupmanager.utils.Tasks; -import org.bukkit.configuration.file.YamlConfiguration; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.SafeConstructor; +import org.yaml.snakeyaml.reader.UnicodeReader; /** * * @author gabrielcouto */ public class GMConfiguration { + + private boolean opOverride; + private boolean toggleValidate; + private Integer saveInterval; + private Integer backupDuration; + private String loggerLevel; + private Map<String, Object> mirrorsMap; + private GroupManager plugin; - private File configFile; - private YamlConfiguration GMconfig; + private Map<String, Object> GMconfig; public GMConfiguration(GroupManager plugin) { @@ -28,12 +38,14 @@ public class GMConfiguration { load(); } + @SuppressWarnings("unchecked") public void load() { if (!plugin.getDataFolder().exists()) { plugin.getDataFolder().mkdirs(); } - configFile = new File(plugin.getDataFolder(), "config.yml"); + + File configFile = new File(plugin.getDataFolder(), "config.yml"); if (!configFile.exists()) { try { @@ -43,59 +55,94 @@ public class GMConfiguration { } } - GMconfig = new YamlConfiguration(); + Yaml configYAML = new Yaml(new SafeConstructor()); try { - GMconfig.load(configFile); + 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); } + /* + * 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"); + + loggerLevel = ((Map<String, String>) getElement("settings", GMconfig).get("logging")).get("level"); + + /* + * Store our mirrors map for parsing later. + */ + mirrorsMap = (Map<String, Object>) ((Map<String, Object>) GMconfig.get("settings")).get("mirrors"); + // Setup defaults adjustLoggerLevel(); plugin.setValidateOnlinePlayer(isToggleValidate()); } + + @SuppressWarnings("unchecked") + private Map<String, Object> getElement(String element, Map<String, Object> map) { + + if (!map.containsKey(element)) { + throw new IllegalArgumentException("The config.yml has no '" + element + ".\n"); + } + + return (Map<String, Object>) map.get(element); + + } public boolean isOpOverride() { - return GMconfig.getBoolean("settings.config.opOverrides", true); + return opOverride; } public boolean isToggleValidate() { - - return GMconfig.getBoolean("settings.config.validate_toggle", true); - } - - public Map<String, Object> getMirrorsMap() { - - // Try to fetch the old mirror path first - if (GMconfig.isConfigurationSection("settings.permission.world.mirror")) { - return (Map<String, Object>) GMconfig.getConfigurationSection("settings.permission.world.mirror").getValues(false); - } else if (GMconfig.isConfigurationSection("settings.mirrors")) { - return (Map<String, Object>) GMconfig.getConfigurationSection("settings.mirrors").getValues(false); - } - return null; - + + return toggleValidate; } public Integer getSaveInterval() { - return GMconfig.getInt("settings.data.save.minutes", 10); + return saveInterval; } public Integer getBackupDuration() { - return GMconfig.getInt("settings.data.save.hours", 24); + return backupDuration; } public void adjustLoggerLevel() { try { - GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO"))); + GroupManager.logger.setLevel(Level.parse(loggerLevel)); return; } catch (Exception e) { } GroupManager.logger.setLevel(Level.INFO); } + + public Map<String, Object> getMirrorsMap() { + + if (!mirrorsMap.isEmpty()) { + return mirrorsMap; + } + return null; + + } + }
\ No newline at end of file |