mirror of
https://github.com/essentials/Essentials.git
synced 2025-10-02 17:16:59 +02:00
Rewrote Config loading to use Bukkits Configuration features
Added an opOverride setting in config. If present and set to false, op's will not get overriding permissions in GroupManager. (one op will not be able to alter another op's settings) GM will now create all relevant world data files for non mirrored worlds. (for all worlds named in config.yml)
This commit is contained in:
90
EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
Executable file → Normal file
90
EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java
Executable file → Normal file
@@ -5,15 +5,11 @@
|
||||
package org.anjocaido.groupmanager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import org.anjocaido.groupmanager.utils.Tasks;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.reader.UnicodeReader;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -22,9 +18,9 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
|
||||
public class GMConfiguration {
|
||||
|
||||
private GroupManager plugin;
|
||||
private Map<String, Object> rootDataNode;
|
||||
private File configFile;
|
||||
|
||||
private Configuration GMconfig;
|
||||
|
||||
public GMConfiguration(GroupManager plugin) {
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
@@ -44,77 +40,37 @@ public class GMConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
Yaml yaml = new Yaml(new SafeConstructor());
|
||||
FileInputStream rx = null;
|
||||
GMconfig = new Configuration(configFile);
|
||||
|
||||
try {
|
||||
rx = new FileInputStream(configFile);
|
||||
} catch (FileNotFoundException ex) {
|
||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
try {
|
||||
rootDataNode = (Map<String, Object>) yaml.load(new UnicodeReader(rx));
|
||||
if (rootDataNode == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
GMconfig.load();
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
|
||||
} finally {
|
||||
try {
|
||||
rx.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
adjustLoggerLevel();
|
||||
}
|
||||
|
||||
public Map<String, Object> getMirrorsMap() {
|
||||
if (rootDataNode.get("settings") instanceof Map) {
|
||||
Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings");
|
||||
if (settingsNode.get("permission") instanceof Map) {
|
||||
Map<String, Object> permissionNode = (Map<String, Object>) settingsNode.get("permission");
|
||||
if (permissionNode.get("world") instanceof Map) {
|
||||
Map<String, Object> worldsNode = (Map<String, Object>) permissionNode.get("world");
|
||||
if (worldsNode.get("mirror") instanceof Map) {
|
||||
Map<String, Object> mirrorsNode = (Map<String, Object>) worldsNode.get("mirror");
|
||||
return mirrorsNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
public boolean isOpOverride() {
|
||||
return GMconfig.getBoolean("settings.config.opOverrides", true);
|
||||
}
|
||||
|
||||
public Integer getSaveInterval() {
|
||||
if (rootDataNode.get("settings") instanceof Map) {
|
||||
Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings");
|
||||
if (settingsNode.get("data") instanceof Map) {
|
||||
Map<String, Object> dataNode = (Map<String, Object>) settingsNode.get("data");
|
||||
if (dataNode.get("save") instanceof Map) {
|
||||
Map<String, Object> saveNode = (Map<String, Object>) dataNode.get("save");
|
||||
if (saveNode.get("minutes") instanceof Integer) {
|
||||
return (Integer) saveNode.get("minutes");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 10;
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getMirrorsMap() {
|
||||
return (Map<String, Object>) GMconfig.getProperty("settings.permission.world.mirror");
|
||||
}
|
||||
|
||||
public Integer getSaveInterval() {
|
||||
return GMconfig.getInt("settings.data.save.minutes", 10);
|
||||
}
|
||||
|
||||
public void adjustLoggerLevel() {
|
||||
if (rootDataNode.get("settings") instanceof Map) {
|
||||
Map<String, Object> settingsNode = (Map<String, Object>) rootDataNode.get("settings");
|
||||
if (settingsNode.get("logging") instanceof Map) {
|
||||
Map<String, Object> loggingNode = (Map<String, Object>) settingsNode.get("logging");
|
||||
if (loggingNode.get("level") instanceof String) {
|
||||
String level = (String) loggingNode.get("level");
|
||||
try {
|
||||
GroupManager.logger.setLevel(Level.parse(level));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
GroupManager.logger.setLevel(Level.INFO);
|
||||
|
||||
GroupManager.logger.setLevel(Level.INFO);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user