mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-15 05:33:40 +00:00
Stop using the YamlConfiguration in bukkit for our config handling. We
can now support periods in world names.
This commit is contained in:
parent
6064b9760b
commit
7b482b612e
2 changed files with 73 additions and 25 deletions
|
@ -191,3 +191,4 @@ v 2.0:
|
||||||
- Stop force removing attachments and let Bukkit handle it's own mess.
|
- 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.
|
- Change to our own Yaml parsing for globalgroups instead of using the YAMLConfiguration class in bukkit.
|
||||||
- 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.
|
|
@ -5,12 +5,15 @@
|
||||||
package org.anjocaido.groupmanager;
|
package org.anjocaido.groupmanager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.utils.Tasks;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -18,9 +21,16 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
*/
|
*/
|
||||||
public class GMConfiguration {
|
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 GroupManager plugin;
|
||||||
private File configFile;
|
private Map<String, Object> GMconfig;
|
||||||
private YamlConfiguration GMconfig;
|
|
||||||
|
|
||||||
public GMConfiguration(GroupManager plugin) {
|
public GMConfiguration(GroupManager plugin) {
|
||||||
|
|
||||||
|
@ -28,12 +38,14 @@ public class GMConfiguration {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
if (!plugin.getDataFolder().exists()) {
|
if (!plugin.getDataFolder().exists()) {
|
||||||
plugin.getDataFolder().mkdirs();
|
plugin.getDataFolder().mkdirs();
|
||||||
}
|
}
|
||||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
|
||||||
|
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
try {
|
try {
|
||||||
|
@ -43,59 +55,94 @@ public class GMConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GMconfig = new YamlConfiguration();
|
Yaml configYAML = new Yaml(new SafeConstructor());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GMconfig.load(configFile);
|
FileInputStream configInputStream = new FileInputStream(configFile);
|
||||||
|
GMconfig = (Map<String, Object>) configYAML.load(new UnicodeReader(configInputStream));
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
// Setup defaults
|
||||||
adjustLoggerLevel();
|
adjustLoggerLevel();
|
||||||
plugin.setValidateOnlinePlayer(isToggleValidate());
|
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() {
|
public boolean isOpOverride() {
|
||||||
|
|
||||||
return GMconfig.getBoolean("settings.config.opOverrides", true);
|
return opOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isToggleValidate() {
|
public boolean isToggleValidate() {
|
||||||
|
|
||||||
return GMconfig.getBoolean("settings.config.validate_toggle", true);
|
return toggleValidate;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getSaveInterval() {
|
public Integer getSaveInterval() {
|
||||||
|
|
||||||
return GMconfig.getInt("settings.data.save.minutes", 10);
|
return saveInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getBackupDuration() {
|
public Integer getBackupDuration() {
|
||||||
|
|
||||||
return GMconfig.getInt("settings.data.save.hours", 24);
|
return backupDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void adjustLoggerLevel() {
|
public void adjustLoggerLevel() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
|
GroupManager.logger.setLevel(Level.parse(loggerLevel));
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupManager.logger.setLevel(Level.INFO);
|
GroupManager.logger.setLevel(Level.INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getMirrorsMap() {
|
||||||
|
|
||||||
|
if (!mirrorsMap.isEmpty()) {
|
||||||
|
return mirrorsMap;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue