summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r--EssentialsGroupManager/src/Changelog.txt3
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java95
2 files changed, 73 insertions, 25 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index bf14359a2..027df85f8 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -190,4 +190,5 @@ v 2.0:
- Throw a better error than 'null' when someone removes all groups from a yml.
- Stop force removing attachments and let Bukkit handle it's own mess.
- Change to our own Yaml parsing for globalgroups instead of using the YAMLConfiguration class in bukkit.
- - Fix a cases sensitivity bug in world loading. \ No newline at end of file
+ - 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. \ No newline at end of file
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