mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 21:25:46 +01:00
Cleaned up configuration handling and added new logging class.
This commit is contained in:
parent
e5556d9138
commit
e28ee185b6
248
src/main/java/org/dynmap/ConfigurationNode.java
Normal file
248
src/main/java/org/dynmap/ConfigurationNode.java
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
package org.dynmap;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class ConfigurationNode implements Map<String, Object> {
|
||||||
|
public Map<String, Object> entries;
|
||||||
|
public ConfigurationNode(org.bukkit.util.config.ConfigurationNode node) {
|
||||||
|
entries = new HashMap<String, Object>();
|
||||||
|
for(String key : node.getKeys(null)) {
|
||||||
|
entries.put(key, node.getProperty(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationNode(Map<String, Object> map) {
|
||||||
|
entries = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObject(String path) {
|
||||||
|
if (path.isEmpty())
|
||||||
|
return entries;
|
||||||
|
int separator = path.indexOf('/');
|
||||||
|
if (separator < 0)
|
||||||
|
return get(path);
|
||||||
|
String localKey = path.substring(0, separator - 1);
|
||||||
|
Object subvalue = get(localKey);
|
||||||
|
if (subvalue == null)
|
||||||
|
return null;
|
||||||
|
if (!(subvalue instanceof Map<?, ?>))
|
||||||
|
return null;
|
||||||
|
Map<String, Object> submap;
|
||||||
|
try {
|
||||||
|
submap = (Map<String, Object>)subvalue;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subpath = path.substring(separator + 1);
|
||||||
|
return new ConfigurationNode(submap).getObject(subpath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObject(String path, Object def) {
|
||||||
|
Object o = getObject(path);
|
||||||
|
if (o == null)
|
||||||
|
return def;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getGeneric(String path, T def) {
|
||||||
|
Object o = getObject(path, def);
|
||||||
|
try {
|
||||||
|
return (T)o;
|
||||||
|
} catch(ClassCastException e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInteger(String path, int def) {
|
||||||
|
return Integer.parseInt(getObject(path, def).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLong(String path, long def) {
|
||||||
|
return Long.parseLong(getObject(path, def).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getFloat(String path, float def) {
|
||||||
|
return Float.parseFloat(getObject(path, def).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDouble(String path, double def) {
|
||||||
|
return Double.parseDouble(getObject(path, def).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean(String path, boolean def) {
|
||||||
|
return Boolean.parseBoolean(getObject(path, def).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String path) {
|
||||||
|
return getString(path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getStrings(String path, List<String> def) {
|
||||||
|
Object o = getObject(path);
|
||||||
|
if (!(o instanceof List<?>)) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
ArrayList<String> strings = new ArrayList<String>();
|
||||||
|
for(Object i : (List<?>)o) {
|
||||||
|
strings.add(i.toString());
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String path, String def) {
|
||||||
|
Object o = getObject(path, def);
|
||||||
|
if (o == null)
|
||||||
|
return null;
|
||||||
|
return o.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getList(String path) {
|
||||||
|
try {
|
||||||
|
List<T> list = (List<T>)getObject(path, null);
|
||||||
|
return list;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
try {
|
||||||
|
T o = (T)getObject(path, null);
|
||||||
|
if (o == null) {
|
||||||
|
return new ArrayList<T>();
|
||||||
|
}
|
||||||
|
ArrayList<T> al = new ArrayList<T>();
|
||||||
|
al.add(o);
|
||||||
|
return al;
|
||||||
|
} catch (ClassCastException e2) {
|
||||||
|
return new ArrayList<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationNode getNode(String path) {
|
||||||
|
Map<String, Object> v = null;
|
||||||
|
v = getGeneric(path, v);
|
||||||
|
if (v == null)
|
||||||
|
return null;
|
||||||
|
return new ConfigurationNode(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ConfigurationNode> getNodes(String path) {
|
||||||
|
Object o = getObject(path);
|
||||||
|
if (!(o instanceof List<?>)) {
|
||||||
|
return new ArrayList<ConfigurationNode>();
|
||||||
|
}
|
||||||
|
ArrayList<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
|
||||||
|
for(Object i : (List<?>)o) {
|
||||||
|
if (i instanceof Map<?, ?>) {
|
||||||
|
Map<String, Object> map;
|
||||||
|
try {
|
||||||
|
map = (Map<String, Object>)i;
|
||||||
|
} catch(ClassCastException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nodes.add(new ConfigurationNode(map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T createInstance(Class<?>[] constructorParameters, Object[] constructorArguments) {
|
||||||
|
String typeName = getString("class");
|
||||||
|
try {
|
||||||
|
Class<?> mapTypeClass = Class.forName(typeName);
|
||||||
|
|
||||||
|
Class<?>[] constructorParameterWithConfiguration = new Class<?>[constructorParameters.length+1];
|
||||||
|
constructorParameterWithConfiguration[constructorParameterWithConfiguration.length-1] = ConfigurationNode.class;
|
||||||
|
|
||||||
|
Object[] constructorArgumentsWithConfiguration = new Object[constructorArguments.length+1];
|
||||||
|
constructorArgumentsWithConfiguration[constructorArgumentsWithConfiguration.length-1] = this;
|
||||||
|
Constructor<?> constructor = mapTypeClass.getConstructor(constructorParameterWithConfiguration);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
T t = (T)constructor.newInstance(constructorArgumentsWithConfiguration);
|
||||||
|
return t;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: Remove reference to MapManager.
|
||||||
|
MapManager.log.log(Level.SEVERE, MapManager.LOG_PREFIX + "Error loading maptype", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> createInstances(String path, Class<?>[] constructorParameters, Object[] constructorArguments) {
|
||||||
|
List<ConfigurationNode> nodes = getNodes(path);
|
||||||
|
List<T> instances = new ArrayList<T>();
|
||||||
|
for(ConfigurationNode node : nodes) {
|
||||||
|
T instance = node.<T>createInstance(constructorParameters, constructorArguments);
|
||||||
|
if (instance != null) {
|
||||||
|
instances.add(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return entries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return entries.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(Object key) {
|
||||||
|
return entries.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
return entries.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get(Object key) {
|
||||||
|
return entries.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object put(String key, Object value) {
|
||||||
|
return entries.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object remove(Object key) {
|
||||||
|
return entries.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(Map<? extends String, ? extends Object> m) {
|
||||||
|
entries.putAll(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> keySet() {
|
||||||
|
return entries.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Object> values() {
|
||||||
|
return entries.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<java.util.Map.Entry<String, Object>> entrySet() {
|
||||||
|
return entries.entrySet();
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,9 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -35,7 +37,6 @@ import org.bukkit.event.world.WorldLoadEvent;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
import org.dynmap.Event.Listener;
|
import org.dynmap.Event.Listener;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
import org.dynmap.debug.Debugger;
|
import org.dynmap.debug.Debugger;
|
||||||
@ -56,7 +57,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
public HttpServer webServer = null;
|
public HttpServer webServer = null;
|
||||||
public MapManager mapManager = null;
|
public MapManager mapManager = null;
|
||||||
public PlayerList playerList;
|
public PlayerList playerList;
|
||||||
public Configuration configuration;
|
public ConfigurationNode configuration;
|
||||||
public HashSet<String> enabledTriggers = new HashSet<String>();
|
public HashSet<String> enabledTriggers = new HashSet<String>();
|
||||||
public PermissionProvider permissions;
|
public PermissionProvider permissions;
|
||||||
public HeroChatHandler hchand;
|
public HeroChatHandler hchand;
|
||||||
@ -81,8 +82,9 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
dataDirectory = this.getDataFolder();
|
dataDirectory = this.getDataFolder();
|
||||||
|
|
||||||
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
org.bukkit.util.config.Configuration bukkitConfiguration = new org.bukkit.util.config.Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
||||||
configuration.load();
|
bukkitConfiguration.load();
|
||||||
|
configuration = new ConfigurationNode(bukkitConfiguration);
|
||||||
|
|
||||||
loadDebuggers();
|
loadDebuggers();
|
||||||
|
|
||||||
@ -103,7 +105,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
if (configuration.getBoolean("jsonfile", false)) {
|
if (configuration.getBoolean("jsonfile", false)) {
|
||||||
jsonConfig();
|
jsonConfig();
|
||||||
int jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000;
|
int jsonInterval = configuration.getInteger("jsonfile-interval", 1) * 1000;
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval);
|
timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval);
|
||||||
}
|
}
|
||||||
@ -111,7 +113,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
hchand = new HeroChatHandler(configuration, this, getServer());
|
hchand = new HeroChatHandler(configuration, this, getServer());
|
||||||
|
|
||||||
enabledTriggers.clear();
|
enabledTriggers.clear();
|
||||||
List<Object> triggers = configuration.getList("render-triggers");
|
List<String> triggers = configuration.getStrings("render-triggers", new ArrayList<String>());
|
||||||
if (triggers != null)
|
if (triggers != null)
|
||||||
{
|
{
|
||||||
for (Object trigger : triggers) {
|
for (Object trigger : triggers) {
|
||||||
@ -138,17 +140,17 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
bindAddress = null;
|
bindAddress = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int port = configuration.getInt("webserver-port", 8123);
|
int port = configuration.getInteger("webserver-port", 8123);
|
||||||
|
|
||||||
webServer = new HttpServer(bindAddress, port);
|
webServer = new HttpServer(bindAddress, port);
|
||||||
webServer.handlers.put("/", new FilesystemHandler(getFile(configuration.getString("webpath", "web"))));
|
webServer.handlers.put("/", new FilesystemHandler(getFile(configuration.getString("webpath", "web"))));
|
||||||
webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory));
|
webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory));
|
||||||
webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer()));
|
webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer()));
|
||||||
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web")));
|
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler(configuration.getNode("web")));
|
||||||
|
|
||||||
if (configuration.getNode("web").getBoolean("allowwebchat", false)) {
|
if (configuration.getNode("web").getBoolean("allowwebchat", false)) {
|
||||||
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
||||||
maximumMessageInterval = (configuration.getNode("web").getInt("webchat-interval", 1) * 1000);
|
maximumMessageInterval = (configuration.getNode("web").getInteger("webchat-interval", 1) * 1000);
|
||||||
spamMessage = "\""+configuration.getNode("web").getString("spammessage", "You may only chat once every %interval% seconds.")+"\"";
|
spamMessage = "\""+configuration.getNode("web").getString("spammessage", "You may only chat once every %interval% seconds.")+"\"";
|
||||||
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||||
@Override
|
@Override
|
||||||
@ -284,23 +286,19 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void loadDebuggers() {
|
protected void loadDebuggers() {
|
||||||
Object debuggersConfiguration = configuration.getProperty("debuggers");
|
List<ConfigurationNode> debuggersConfiguration = configuration.getNodes("debuggers");
|
||||||
Debug.clearDebuggers();
|
Debug.clearDebuggers();
|
||||||
if (debuggersConfiguration != null) {
|
for (ConfigurationNode debuggerConfiguration : debuggersConfiguration) {
|
||||||
for (Object debuggerConfiguration : (List<?>) debuggersConfiguration) {
|
|
||||||
Map<?, ?> debuggerConfigurationMap = (Map<?, ?>) debuggerConfiguration;
|
|
||||||
try {
|
try {
|
||||||
Class<?> debuggerClass = Class.forName((String) debuggerConfigurationMap.get("class"));
|
Class<?> debuggerClass = Class.forName((String) debuggerConfiguration.getString("class"));
|
||||||
Constructor<?> constructor = debuggerClass.getConstructor(JavaPlugin.class, Map.class);
|
Constructor<?> constructor = debuggerClass.getConstructor(JavaPlugin.class, Map.class);
|
||||||
Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfigurationMap);
|
Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfiguration);
|
||||||
Debug.addDebugger(debugger);
|
Debug.addDebugger(debugger);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.severe(LOG_PREFIX + "Error loading debugger: " + e);
|
log.severe(LOG_PREFIX + "Error loading debugger: " + e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +389,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private void jsonConfig() {
|
private void jsonConfig() {
|
||||||
File outputFile;
|
File outputFile;
|
||||||
Map<?, ?> clientConfig = (Map<?, ?>) configuration.getProperty("web");
|
ConfigurationNode clientConfig = configuration.getNode("web");
|
||||||
File webpath = new File(configuration.getString("webpath", "web"), "standalone/dynmap_config.json");
|
File webpath = new File(configuration.getString("webpath", "web"), "standalone/dynmap_config.json");
|
||||||
if (webpath.isAbsolute())
|
if (webpath.isAbsolute())
|
||||||
outputFile = webpath;
|
outputFile = webpath;
|
||||||
|
@ -11,7 +11,6 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
|
|
||||||
public class HeroChatHandler {
|
public class HeroChatHandler {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
@ -227,13 +226,13 @@ public class HeroChatHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeroChatHandler(Configuration cfg, DynmapPlugin plugin, Server server) {
|
public HeroChatHandler(ConfigurationNode cfg, DynmapPlugin plugin, Server server) {
|
||||||
/* If we're enabling hero chat support */
|
/* If we're enabling hero chat support */
|
||||||
if (cfg.getNode("web").getBoolean("enableherochat", false)) {
|
if (cfg.getNode("web").getBoolean("enableherochat", false)) {
|
||||||
log.info(LOG_PREFIX + "HeroChat support configured");
|
log.info(LOG_PREFIX + "HeroChat support configured");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
/* Now, get the monitored channel list */
|
/* Now, get the monitored channel list */
|
||||||
hcchannels = cfg.getNode("web").getStringList("herochatchannels",
|
hcchannels = cfg.getStrings("web/herochatchannels",
|
||||||
DEF_CHANNELS);
|
DEF_CHANNELS);
|
||||||
/* And get channel to send web messages */
|
/* And get channel to send web messages */
|
||||||
hcwebinputchannel = cfg.getNode("web").getString(
|
hcwebinputchannel = cfg.getNode("web").getString(
|
||||||
|
@ -15,8 +15,6 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
import org.bukkit.util.config.ConfigurationNode;
|
|
||||||
import org.dynmap.web.Json;
|
import org.dynmap.web.Json;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
@ -30,17 +28,17 @@ class JsonTimerTask extends TimerTask {
|
|||||||
private final DynmapPlugin plugin;
|
private final DynmapPlugin plugin;
|
||||||
private Server server;
|
private Server server;
|
||||||
private MapManager mapManager;
|
private MapManager mapManager;
|
||||||
private Configuration configuration;
|
private ConfigurationNode configuration;
|
||||||
private ConfigurationNode regions;
|
private ConfigurationNode regions;
|
||||||
private static final JSONParser parser = new JSONParser();
|
private static final JSONParser parser = new JSONParser();
|
||||||
private long lastTimestamp = 0;
|
private long lastTimestamp = 0;
|
||||||
|
|
||||||
public JsonTimerTask(DynmapPlugin instance, Configuration config) {
|
public JsonTimerTask(DynmapPlugin instance, ConfigurationNode config) {
|
||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
this.server = this.plugin.getServer();
|
this.server = this.plugin.getServer();
|
||||||
this.mapManager = this.plugin.getMapManager();
|
this.mapManager = this.plugin.getMapManager();
|
||||||
this.configuration = config;
|
this.configuration = config;
|
||||||
for(ConfigurationNode type : configuration.getNodeList("web.components", null))
|
for(ConfigurationNode type : configuration.getNodes("web/components"))
|
||||||
if(type.getString("type").equalsIgnoreCase("regions")) {
|
if(type.getString("type").equalsIgnoreCase("regions")) {
|
||||||
this.regions = type;
|
this.regions = type;
|
||||||
break;
|
break;
|
||||||
@ -48,7 +46,7 @@ class JsonTimerTask extends TimerTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
long jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000;
|
long jsonInterval = configuration.getInteger("jsonfile-interval", 1) * 1000;
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
File outputFile;
|
File outputFile;
|
||||||
|
|
||||||
@ -138,16 +136,16 @@ class JsonTimerTask extends TimerTask {
|
|||||||
private void parseRegionFile(String regionFile, String outputFileName)
|
private void parseRegionFile(String regionFile, String outputFileName)
|
||||||
{
|
{
|
||||||
File outputFile;
|
File outputFile;
|
||||||
Configuration regionConfig = null;
|
org.bukkit.util.config.Configuration regionConfig = null;
|
||||||
if(regions.getBoolean("useworldpath", false))
|
if(regions.getBoolean("useworldpath", false))
|
||||||
{
|
{
|
||||||
if(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile).exists())
|
if(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile).exists())
|
||||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
regionConfig = new org.bukkit.util.config.Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
||||||
else if(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile).exists())
|
else if(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile).exists())
|
||||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile));
|
regionConfig = new org.bukkit.util.config.Configuration(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
regionConfig = new org.bukkit.util.config.Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
||||||
//File didn't exist
|
//File didn't exist
|
||||||
if(regionConfig == null)
|
if(regionConfig == null)
|
||||||
return;
|
return;
|
||||||
|
27
src/main/java/org/dynmap/Log.java
Normal file
27
src/main/java/org/dynmap/Log.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.dynmap;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class Log {
|
||||||
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
protected static final String LOG_PREFIX = "[dynmap] ";
|
||||||
|
public static void info(String msg) {
|
||||||
|
log.info(msg);
|
||||||
|
}
|
||||||
|
public static void severe(Exception e) {
|
||||||
|
log.log(Level.SEVERE, LOG_PREFIX + "Exception occured: ", e);
|
||||||
|
}
|
||||||
|
public static void severe(String msg) {
|
||||||
|
log.log(Level.SEVERE, LOG_PREFIX + msg);
|
||||||
|
}
|
||||||
|
public static void severe(String msg, Exception e) {
|
||||||
|
log.log(Level.SEVERE, LOG_PREFIX + msg, e);
|
||||||
|
}
|
||||||
|
public static void warning(String msg) {
|
||||||
|
log.log(Level.WARNING, LOG_PREFIX + msg);
|
||||||
|
}
|
||||||
|
public static void warning(String msg, Exception e) {
|
||||||
|
log.log(Level.WARNING, LOG_PREFIX + msg, e);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.util.config.ConfigurationNode;
|
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
|
|
||||||
public class MapManager {
|
public class MapManager {
|
||||||
@ -78,7 +77,7 @@ public class MapManager {
|
|||||||
/* If render queue is empty, start next map */
|
/* If render queue is empty, start next map */
|
||||||
if(renderQueue.isEmpty()) {
|
if(renderQueue.isEmpty()) {
|
||||||
if(map_index >= 0) { /* Finished a map? */
|
if(map_index >= 0) { /* Finished a map? */
|
||||||
log.info(LOG_PREFIX + "Full render of map '" + world.maps.get(map_index).getClass().getSimpleName() + "' of world '" +
|
Log.info("Full render of map '" + world.maps.get(map_index).getClass().getSimpleName() + "' of world '" +
|
||||||
world.world.getName() + "' completed - " + rendercnt + " tiles rendered.");
|
world.world.getName() + "' completed - " + rendercnt + " tiles rendered.");
|
||||||
}
|
}
|
||||||
found.clear();
|
found.clear();
|
||||||
@ -133,7 +132,7 @@ public class MapManager {
|
|||||||
found.remove(tile);
|
found.remove(tile);
|
||||||
rendercnt++;
|
rendercnt++;
|
||||||
if((rendercnt % 100) == 0) {
|
if((rendercnt % 100) == 0) {
|
||||||
log.info(LOG_PREFIX + "Full render of map '" + world.maps.get(map_index).getClass().getSimpleName() + "' on world '" +
|
Log.info("Full render of map '" + world.maps.get(map_index).getClass().getSimpleName() + "' on world '" +
|
||||||
w.getName() + "' in progress - " + rendercnt + " tiles rendered, " + renderQueue.size() + " tiles pending.");
|
w.getName() + "' in progress - " + rendercnt + " tiles rendered, " + renderQueue.size() + " tiles pending.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,15 +187,24 @@ public class MapManager {
|
|||||||
timeslice_interval = configuration.getDouble("timesliceinterval", 0.5);
|
timeslice_interval = configuration.getDouble("timesliceinterval", 0.5);
|
||||||
do_sync_render = configuration.getBoolean("renderonsync", true);
|
do_sync_render = configuration.getBoolean("renderonsync", true);
|
||||||
|
|
||||||
for(Object worldConfigurationObj : (List<?>)configuration.getProperty("worlds")) {
|
for(ConfigurationNode worldConfiguration : configuration.getNodes("worlds")) {
|
||||||
Map<?, ?> worldConfiguration = (Map<?, ?>)worldConfigurationObj;
|
String worldName = worldConfiguration.getString("name");
|
||||||
String worldName = (String)worldConfiguration.get("name");
|
|
||||||
DynmapWorld world = new DynmapWorld();
|
DynmapWorld world = new DynmapWorld();
|
||||||
if (worldConfiguration.get("maps") != null) {
|
|
||||||
for(MapType map : loadMapTypes((List<?>)worldConfiguration.get("maps"))) {
|
Event.Listener<MapTile> invalitateListener = new Event.Listener<MapTile>() {
|
||||||
|
@Override
|
||||||
|
public void triggered(MapTile t) {
|
||||||
|
invalidateTile(t);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
log.info(LOG_PREFIX + "Loading maps of world '" + worldName + "'...");
|
||||||
|
for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[0], new Object[0])) {
|
||||||
|
map.onTileInvalidated.addListener(invalitateListener);
|
||||||
world.maps.add(map);
|
world.maps.add(map);
|
||||||
}
|
}
|
||||||
}
|
log.info(LOG_PREFIX + "Loaded " + world.maps.size() + " maps of world '" + worldName + "'.");
|
||||||
|
|
||||||
inactiveworlds.put(worldName, world);
|
inactiveworlds.put(worldName, world);
|
||||||
|
|
||||||
World bukkitWorld = plugin.getServer().getWorld(worldName);
|
World bukkitWorld = plugin.getServer().getWorld(worldName);
|
||||||
@ -307,35 +315,6 @@ public class MapManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapType[] loadMapTypes(List<?> mapConfigurations) {
|
|
||||||
Event.Listener<MapTile> invalitateListener = new Event.Listener<MapTile>() {
|
|
||||||
@Override
|
|
||||||
public void triggered(MapTile t) {
|
|
||||||
invalidateTile(t);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
|
||||||
for (Object configuredMapObj : mapConfigurations) {
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> configuredMap = (Map<String, Object>) configuredMapObj;
|
|
||||||
String typeName = (String) configuredMap.get("class");
|
|
||||||
log.info(LOG_PREFIX + "Loading map '" + typeName.toString() + "'...");
|
|
||||||
Class<?> mapTypeClass = Class.forName(typeName);
|
|
||||||
Constructor<?> constructor = mapTypeClass.getConstructor(Map.class);
|
|
||||||
MapType mapType = (MapType) constructor.newInstance(configuredMap);
|
|
||||||
mapType.onTileInvalidated.addListener(invalitateListener);
|
|
||||||
mapTypes.add(mapType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.log(Level.SEVERE, LOG_PREFIX + "Error loading maptype", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MapType[] result = new MapType[mapTypes.size()];
|
|
||||||
mapTypes.toArray(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int touch(Location l) {
|
public int touch(Location l) {
|
||||||
DynmapWorld world = worlds.get(l.getWorld().getName());
|
DynmapWorld world = worlds.get(l.getWorld().getName());
|
||||||
if (world == null)
|
if (world == null)
|
||||||
|
@ -12,15 +12,14 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
|
|
||||||
public class PlayerList {
|
public class PlayerList {
|
||||||
private Server server;
|
private Server server;
|
||||||
private HashSet<String> hiddenPlayerNames = new HashSet<String>();
|
private HashSet<String> hiddenPlayerNames = new HashSet<String>();
|
||||||
private File hiddenPlayersFile;
|
private File hiddenPlayersFile;
|
||||||
private Configuration configuration;
|
private ConfigurationNode configuration;
|
||||||
|
|
||||||
public PlayerList(Server server, File hiddenPlayersFile, Configuration configuration) {
|
public PlayerList(Server server, File hiddenPlayersFile, ConfigurationNode configuration) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.hiddenPlayersFile = hiddenPlayersFile;
|
this.hiddenPlayersFile = hiddenPlayersFile;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
@ -5,12 +5,13 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
|
|
||||||
public class LogDebugger implements Debugger {
|
public class LogDebugger implements Debugger {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
protected static final String LOG_PREFIX = "[dynmap] ";
|
protected static final String LOG_PREFIX = "[dynmap] ";
|
||||||
|
|
||||||
public LogDebugger(JavaPlugin plugin, Map<String, Object> configuration) {
|
public LogDebugger(JavaPlugin plugin, ConfigurationNode configuration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,11 +3,12 @@ package org.dynmap.debug;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
|
|
||||||
public class NullDebugger implements Debugger {
|
public class NullDebugger implements Debugger {
|
||||||
public static final NullDebugger instance = new NullDebugger(null, null);
|
public static final NullDebugger instance = new NullDebugger(null, null);
|
||||||
|
|
||||||
public NullDebugger(JavaPlugin plugin, Map<String, Object> configuration) {
|
public NullDebugger(JavaPlugin plugin, ConfigurationNode configuration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
|
@ -14,6 +14,7 @@ import org.bukkit.World.Environment;
|
|||||||
import org.dynmap.Client;
|
import org.dynmap.Client;
|
||||||
import org.dynmap.Color;
|
import org.dynmap.Color;
|
||||||
import org.dynmap.ColorScheme;
|
import org.dynmap.ColorScheme;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
import org.dynmap.DynmapChunk;
|
import org.dynmap.DynmapChunk;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
@ -25,7 +26,7 @@ public class FlatMap extends MapType {
|
|||||||
private ColorScheme colorScheme;
|
private ColorScheme colorScheme;
|
||||||
private int maximumHeight = 127;
|
private int maximumHeight = 127;
|
||||||
|
|
||||||
public FlatMap(Map<String, Object> configuration) {
|
public FlatMap(ConfigurationNode configuration) {
|
||||||
prefix = (String) configuration.get("prefix");
|
prefix = (String) configuration.get("prefix");
|
||||||
colorScheme = ColorScheme.getScheme((String) configuration.get("colorscheme"));
|
colorScheme = ColorScheme.getScheme((String) configuration.get("colorscheme"));
|
||||||
Object o = configuration.get("maximumheight");
|
Object o = configuration.get("maximumheight");
|
||||||
|
@ -4,10 +4,11 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.Color;
|
import org.dynmap.Color;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
|
|
||||||
public class CaveTileRenderer extends DefaultTileRenderer {
|
public class CaveTileRenderer extends DefaultTileRenderer {
|
||||||
|
|
||||||
public CaveTileRenderer(Map<String, Object> configuration) {
|
public CaveTileRenderer(ConfigurationNode configuration) {
|
||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import org.bukkit.World.Environment;
|
|||||||
import org.dynmap.Client;
|
import org.dynmap.Client;
|
||||||
import org.dynmap.Color;
|
import org.dynmap.Color;
|
||||||
import org.dynmap.ColorScheme;
|
import org.dynmap.ColorScheme;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultTileRenderer(Map<String, Object> configuration) {
|
public DefaultTileRenderer(ConfigurationNode configuration) {
|
||||||
name = (String) configuration.get("prefix");
|
name = (String) configuration.get("prefix");
|
||||||
Object o = configuration.get("maximumheight");
|
Object o = configuration.get("maximumheight");
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
|
@ -6,19 +6,16 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.Color;
|
import org.dynmap.Color;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
|
|
||||||
public class HighlightTileRenderer extends DefaultTileRenderer {
|
public class HighlightTileRenderer extends DefaultTileRenderer {
|
||||||
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
|
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
|
||||||
|
|
||||||
public HighlightTileRenderer(Map<String, Object> configuration) {
|
public HighlightTileRenderer(ConfigurationNode configuration) {
|
||||||
super(configuration);
|
super(configuration);
|
||||||
Object highlightObj = configuration.get("highlight");
|
List<Integer> highlight = configuration.<Integer>getList("highlight");
|
||||||
if (highlightObj instanceof List<?>) {
|
for(Integer i : highlight) {
|
||||||
for(Object o : (List<?>)highlightObj) {
|
highlightBlocks.add(i);
|
||||||
highlightBlocks.add((Integer)o);
|
|
||||||
}
|
|
||||||
} else if (highlightObj instanceof Integer) {
|
|
||||||
highlightBlocks.add((Integer)highlightObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.dynmap.ConfigurationNode;
|
||||||
import org.dynmap.DynmapChunk;
|
import org.dynmap.DynmapChunk;
|
||||||
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
import org.dynmap.MapType;
|
import org.dynmap.MapType;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
@ -37,32 +39,14 @@ public class KzedMap extends MapType {
|
|||||||
MapTileRenderer[] renderers;
|
MapTileRenderer[] renderers;
|
||||||
ZoomedTileRenderer zoomrenderer;
|
ZoomedTileRenderer zoomrenderer;
|
||||||
|
|
||||||
public KzedMap(Map<String, Object> configuration) {
|
public KzedMap(ConfigurationNode configuration) {
|
||||||
renderers = loadRenderers(configuration);
|
log.info(LOG_PREFIX + "Loading renderers for map '" + getClass().toString() + "'...");
|
||||||
zoomrenderer = new ZoomedTileRenderer(configuration);
|
List<MapTileRenderer> renderers = configuration.<MapTileRenderer>createInstances("renderers", new Class<?>[0], new Object[0]);
|
||||||
}
|
this.renderers = new MapTileRenderer[renderers.size()];
|
||||||
|
renderers.toArray(this.renderers);
|
||||||
|
log.info(LOG_PREFIX + "Loaded " + renderers.size() + " renderers for map '" + getClass().toString() + "'.");
|
||||||
|
|
||||||
private MapTileRenderer[] loadRenderers(Map<String, Object> configuration) {
|
zoomrenderer = new ZoomedTileRenderer(configuration);
|
||||||
List<?> configuredRenderers = (List<?>) configuration.get("renderers");
|
|
||||||
ArrayList<MapTileRenderer> renderers = new ArrayList<MapTileRenderer>();
|
|
||||||
for (Object configuredRendererObj : configuredRenderers) {
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> configuredRenderer = (Map<String, Object>) configuredRendererObj;
|
|
||||||
String typeName = (String) configuredRenderer.get("class");
|
|
||||||
log.info(LOG_PREFIX + "Loading renderer '" + typeName.toString() + "'...");
|
|
||||||
Class<?> mapTypeClass = Class.forName(typeName);
|
|
||||||
Constructor<?> constructor = mapTypeClass.getConstructor(Map.class);
|
|
||||||
MapTileRenderer mapTileRenderer = (MapTileRenderer) constructor.newInstance(configuredRenderer);
|
|
||||||
renderers.add(mapTileRenderer);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Debug.error("Error loading renderer", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MapTileRenderer[] result = new MapTileRenderer[renderers.size()];
|
|
||||||
renderers.toArray(result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +23,8 @@ public class Json {
|
|||||||
s.append("\"" + ((String)o).replace("\"", "\\\"") + "\"");
|
s.append("\"" + ((String)o).replace("\"", "\\\"") + "\"");
|
||||||
} else if (o instanceof Integer || o instanceof Long || o instanceof Float || o instanceof Double) {
|
} else if (o instanceof Integer || o instanceof Long || o instanceof Float || o instanceof Double) {
|
||||||
s.append(o.toString());
|
s.append(o.toString());
|
||||||
} else if (o instanceof LinkedHashMap<?, ?>) {
|
} else if (o instanceof Map<?, ?>) {
|
||||||
LinkedHashMap<?, ?> m = (LinkedHashMap<?, ?>) o;
|
Map<?, ?> m = (Map<?, ?>) o;
|
||||||
s.append("{");
|
s.append("{");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user