From e28ee185b690c5483b576eca2cec06402bc43708 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Wed, 18 May 2011 13:51:27 +0200 Subject: [PATCH] Cleaned up configuration handling and added new logging class. --- .../java/org/dynmap/ConfigurationNode.java | 248 ++++++++++++++++++ src/main/java/org/dynmap/DynmapPlugin.java | 50 ++-- src/main/java/org/dynmap/HeroChatHandler.java | 5 +- src/main/java/org/dynmap/JsonTimerTask.java | 18 +- src/main/java/org/dynmap/Log.java | 27 ++ src/main/java/org/dynmap/MapManager.java | 55 ++-- src/main/java/org/dynmap/PlayerList.java | 5 +- .../java/org/dynmap/debug/LogDebugger.java | 3 +- .../java/org/dynmap/debug/NullDebugger.java | 3 +- src/main/java/org/dynmap/flat/FlatMap.java | 3 +- .../org/dynmap/kzedmap/CaveTileRenderer.java | 3 +- .../dynmap/kzedmap/DefaultTileRenderer.java | 3 +- .../dynmap/kzedmap/HighlightTileRenderer.java | 13 +- src/main/java/org/dynmap/kzedmap/KzedMap.java | 34 +-- src/main/java/org/dynmap/web/Json.java | 4 +- 15 files changed, 354 insertions(+), 120 deletions(-) create mode 100644 src/main/java/org/dynmap/ConfigurationNode.java create mode 100644 src/main/java/org/dynmap/Log.java diff --git a/src/main/java/org/dynmap/ConfigurationNode.java b/src/main/java/org/dynmap/ConfigurationNode.java new file mode 100644 index 00000000..5fcd086b --- /dev/null +++ b/src/main/java/org/dynmap/ConfigurationNode.java @@ -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 { + public Map entries; + public ConfigurationNode(org.bukkit.util.config.ConfigurationNode node) { + entries = new HashMap(); + for(String key : node.getKeys(null)) { + entries.put(key, node.getProperty(key)); + } + } + + public ConfigurationNode(Map 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 submap; + try { + submap = (Map)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 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 getStrings(String path, List def) { + Object o = getObject(path); + if (!(o instanceof List)) { + return def; + } + ArrayList strings = new ArrayList(); + 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 List getList(String path) { + try { + List list = (List)getObject(path, null); + return list; + } catch (ClassCastException e) { + try { + T o = (T)getObject(path, null); + if (o == null) { + return new ArrayList(); + } + ArrayList al = new ArrayList(); + al.add(o); + return al; + } catch (ClassCastException e2) { + return new ArrayList(); + } + } + } + + public ConfigurationNode getNode(String path) { + Map v = null; + v = getGeneric(path, v); + if (v == null) + return null; + return new ConfigurationNode(v); + } + + public List getNodes(String path) { + Object o = getObject(path); + if (!(o instanceof List)) { + return new ArrayList(); + } + ArrayList nodes = new ArrayList(); + for(Object i : (List)o) { + if (i instanceof Map) { + Map map; + try { + map = (Map)i; + } catch(ClassCastException e) { + continue; + } + nodes.add(new ConfigurationNode(map)); + } + } + return nodes; + } + + public 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 List createInstances(String path, Class[] constructorParameters, Object[] constructorArguments) { + List nodes = getNodes(path); + List instances = new ArrayList(); + for(ConfigurationNode node : nodes) { + T instance = node.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 m) { + entries.putAll(m); + } + + @Override + public void clear() { + entries.clear(); + } + + @Override + public Set keySet() { + return entries.keySet(); + } + + @Override + public Collection values() { + return entries.values(); + } + + @Override + public Set> entrySet() { + return entries.entrySet(); + } +} diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 3d8ccdc7..e8710411 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -7,7 +7,9 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -35,7 +37,6 @@ import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.config.Configuration; import org.dynmap.Event.Listener; import org.dynmap.debug.Debug; import org.dynmap.debug.Debugger; @@ -56,7 +57,7 @@ public class DynmapPlugin extends JavaPlugin { public HttpServer webServer = null; public MapManager mapManager = null; public PlayerList playerList; - public Configuration configuration; + public ConfigurationNode configuration; public HashSet enabledTriggers = new HashSet(); public PermissionProvider permissions; public HeroChatHandler hchand; @@ -65,7 +66,7 @@ public class DynmapPlugin extends JavaPlugin { public static File dataDirectory; public static File tilesDirectory; - + public MapManager getMapManager() { return mapManager; } @@ -81,8 +82,9 @@ public class DynmapPlugin extends JavaPlugin { dataDirectory = this.getDataFolder(); - configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); - configuration.load(); + org.bukkit.util.config.Configuration bukkitConfiguration = new org.bukkit.util.config.Configuration(new File(this.getDataFolder(), "configuration.txt")); + bukkitConfiguration.load(); + configuration = new ConfigurationNode(bukkitConfiguration); loadDebuggers(); @@ -103,7 +105,7 @@ public class DynmapPlugin extends JavaPlugin { if (configuration.getBoolean("jsonfile", false)) { jsonConfig(); - int jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000; + int jsonInterval = configuration.getInteger("jsonfile-interval", 1) * 1000; timer = new Timer(); timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval); } @@ -111,7 +113,7 @@ public class DynmapPlugin extends JavaPlugin { hchand = new HeroChatHandler(configuration, this, getServer()); enabledTriggers.clear(); - List triggers = configuration.getList("render-triggers"); + List triggers = configuration.getStrings("render-triggers", new ArrayList()); if (triggers != null) { for (Object trigger : triggers) { @@ -138,17 +140,17 @@ public class DynmapPlugin extends JavaPlugin { bindAddress = null; } } - int port = configuration.getInt("webserver-port", 8123); + int port = configuration.getInteger("webserver-port", 8123); webServer = new HttpServer(bindAddress, port); webServer.handlers.put("/", new FilesystemHandler(getFile(configuration.getString("webpath", "web")))); webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory)); 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)) { 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.")+"\""; onMessageReceived.addListener(new Listener() { @Override @@ -284,22 +286,18 @@ public class DynmapPlugin extends JavaPlugin { } protected void loadDebuggers() { - Object debuggersConfiguration = configuration.getProperty("debuggers"); + List debuggersConfiguration = configuration.getNodes("debuggers"); Debug.clearDebuggers(); - if (debuggersConfiguration != null) { - for (Object debuggerConfiguration : (List) debuggersConfiguration) { - Map debuggerConfigurationMap = (Map) debuggerConfiguration; - try { - Class debuggerClass = Class.forName((String) debuggerConfigurationMap.get("class")); - Constructor constructor = debuggerClass.getConstructor(JavaPlugin.class, Map.class); - Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfigurationMap); - Debug.addDebugger(debugger); - } catch (Exception e) { - log.severe(LOG_PREFIX + "Error loading debugger: " + e); - e.printStackTrace(); - continue; - } - + for (ConfigurationNode debuggerConfiguration : debuggersConfiguration) { + try { + Class debuggerClass = Class.forName((String) debuggerConfiguration.getString("class")); + Constructor constructor = debuggerClass.getConstructor(JavaPlugin.class, Map.class); + Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfiguration); + Debug.addDebugger(debugger); + } catch (Exception e) { + log.severe(LOG_PREFIX + "Error loading debugger: " + e); + e.printStackTrace(); + continue; } } } @@ -391,7 +389,7 @@ public class DynmapPlugin extends JavaPlugin { private void jsonConfig() { 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"); if (webpath.isAbsolute()) outputFile = webpath; diff --git a/src/main/java/org/dynmap/HeroChatHandler.java b/src/main/java/org/dynmap/HeroChatHandler.java index e764e091..cc0aeffa 100644 --- a/src/main/java/org/dynmap/HeroChatHandler.java +++ b/src/main/java/org/dynmap/HeroChatHandler.java @@ -11,7 +11,6 @@ import org.bukkit.event.Event; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.Plugin; -import org.bukkit.util.config.Configuration; public class HeroChatHandler { 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 (cfg.getNode("web").getBoolean("enableherochat", false)) { log.info(LOG_PREFIX + "HeroChat support configured"); this.plugin = plugin; /* Now, get the monitored channel list */ - hcchannels = cfg.getNode("web").getStringList("herochatchannels", + hcchannels = cfg.getStrings("web/herochatchannels", DEF_CHANNELS); /* And get channel to send web messages */ hcwebinputchannel = cfg.getNode("web").getString( diff --git a/src/main/java/org/dynmap/JsonTimerTask.java b/src/main/java/org/dynmap/JsonTimerTask.java index bd5f9841..2666ca1b 100644 --- a/src/main/java/org/dynmap/JsonTimerTask.java +++ b/src/main/java/org/dynmap/JsonTimerTask.java @@ -15,8 +15,6 @@ import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.util.config.Configuration; -import org.bukkit.util.config.ConfigurationNode; import org.dynmap.web.Json; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -30,17 +28,17 @@ class JsonTimerTask extends TimerTask { private final DynmapPlugin plugin; private Server server; private MapManager mapManager; - private Configuration configuration; + private ConfigurationNode configuration; private ConfigurationNode regions; private static final JSONParser parser = new JSONParser(); private long lastTimestamp = 0; - public JsonTimerTask(DynmapPlugin instance, Configuration config) { + public JsonTimerTask(DynmapPlugin instance, ConfigurationNode config) { this.plugin = instance; this.server = this.plugin.getServer(); this.mapManager = this.plugin.getMapManager(); this.configuration = config; - for(ConfigurationNode type : configuration.getNodeList("web.components", null)) + for(ConfigurationNode type : configuration.getNodes("web/components")) if(type.getString("type").equalsIgnoreCase("regions")) { this.regions = type; break; @@ -48,7 +46,7 @@ class JsonTimerTask extends TimerTask { } public void run() { - long jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000; + long jsonInterval = configuration.getInteger("jsonfile-interval", 1) * 1000; long current = System.currentTimeMillis(); File outputFile; @@ -138,16 +136,16 @@ class JsonTimerTask extends TimerTask { private void parseRegionFile(String regionFile, String outputFileName) { File outputFile; - Configuration regionConfig = null; + org.bukkit.util.config.Configuration regionConfig = null; if(regions.getBoolean("useworldpath", false)) { 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()) - 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 - 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 if(regionConfig == null) return; diff --git a/src/main/java/org/dynmap/Log.java b/src/main/java/org/dynmap/Log.java new file mode 100644 index 00000000..2d982638 --- /dev/null +++ b/src/main/java/org/dynmap/Log.java @@ -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); + } +} diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 311cefd9..e2395292 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -16,7 +16,6 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debug; public class MapManager { @@ -78,7 +77,7 @@ public class MapManager { /* If render queue is empty, start next map */ if(renderQueue.isEmpty()) { 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."); } found.clear(); @@ -133,7 +132,7 @@ public class MapManager { found.remove(tile); rendercnt++; 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."); } } @@ -188,15 +187,24 @@ public class MapManager { timeslice_interval = configuration.getDouble("timesliceinterval", 0.5); do_sync_render = configuration.getBoolean("renderonsync", true); - for(Object worldConfigurationObj : (List)configuration.getProperty("worlds")) { - Map worldConfiguration = (Map)worldConfigurationObj; - String worldName = (String)worldConfiguration.get("name"); + for(ConfigurationNode worldConfiguration : configuration.getNodes("worlds")) { + String worldName = worldConfiguration.getString("name"); DynmapWorld world = new DynmapWorld(); - if (worldConfiguration.get("maps") != null) { - for(MapType map : loadMapTypes((List)worldConfiguration.get("maps"))) { - world.maps.add(map); + + Event.Listener invalitateListener = new Event.Listener() { + @Override + public void triggered(MapTile t) { + invalidateTile(t); } + }; + + log.info(LOG_PREFIX + "Loading maps of world '" + worldName + "'..."); + for(MapType map : worldConfiguration.createInstances("maps", new Class[0], new Object[0])) { + map.onTileInvalidated.addListener(invalitateListener); + world.maps.add(map); } + log.info(LOG_PREFIX + "Loaded " + world.maps.size() + " maps of world '" + worldName + "'."); + inactiveworlds.put(worldName, world); World bukkitWorld = plugin.getServer().getWorld(worldName); @@ -307,35 +315,6 @@ public class MapManager { } } - private MapType[] loadMapTypes(List mapConfigurations) { - Event.Listener invalitateListener = new Event.Listener() { - @Override - public void triggered(MapTile t) { - invalidateTile(t); - } - }; - ArrayList mapTypes = new ArrayList(); - for (Object configuredMapObj : mapConfigurations) { - try { - @SuppressWarnings("unchecked") - Map configuredMap = (Map) 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) { DynmapWorld world = worlds.get(l.getWorld().getName()); if (world == null) diff --git a/src/main/java/org/dynmap/PlayerList.java b/src/main/java/org/dynmap/PlayerList.java index 75e6f3e6..090e6daf 100644 --- a/src/main/java/org/dynmap/PlayerList.java +++ b/src/main/java/org/dynmap/PlayerList.java @@ -12,15 +12,14 @@ import java.util.Scanner; import org.bukkit.Server; import org.bukkit.entity.Player; -import org.bukkit.util.config.Configuration; public class PlayerList { private Server server; private HashSet hiddenPlayerNames = new HashSet(); 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.hiddenPlayersFile = hiddenPlayersFile; this.configuration = configuration; diff --git a/src/main/java/org/dynmap/debug/LogDebugger.java b/src/main/java/org/dynmap/debug/LogDebugger.java index b5c52dd8..2ac8d025 100644 --- a/src/main/java/org/dynmap/debug/LogDebugger.java +++ b/src/main/java/org/dynmap/debug/LogDebugger.java @@ -5,12 +5,13 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.plugin.java.JavaPlugin; +import org.dynmap.ConfigurationNode; public class LogDebugger implements Debugger { protected static final Logger log = Logger.getLogger("Minecraft"); protected static final String LOG_PREFIX = "[dynmap] "; - public LogDebugger(JavaPlugin plugin, Map configuration) { + public LogDebugger(JavaPlugin plugin, ConfigurationNode configuration) { } @Override diff --git a/src/main/java/org/dynmap/debug/NullDebugger.java b/src/main/java/org/dynmap/debug/NullDebugger.java index 7b4b689a..485790c6 100644 --- a/src/main/java/org/dynmap/debug/NullDebugger.java +++ b/src/main/java/org/dynmap/debug/NullDebugger.java @@ -3,11 +3,12 @@ package org.dynmap.debug; import java.util.Map; import org.bukkit.plugin.java.JavaPlugin; +import org.dynmap.ConfigurationNode; public class NullDebugger implements Debugger { public static final NullDebugger instance = new NullDebugger(null, null); - public NullDebugger(JavaPlugin plugin, Map configuration) { + public NullDebugger(JavaPlugin plugin, ConfigurationNode configuration) { } public void debug(String message) { diff --git a/src/main/java/org/dynmap/flat/FlatMap.java b/src/main/java/org/dynmap/flat/FlatMap.java index 895c46be..1aaef2d7 100644 --- a/src/main/java/org/dynmap/flat/FlatMap.java +++ b/src/main/java/org/dynmap/flat/FlatMap.java @@ -14,6 +14,7 @@ import org.bukkit.World.Environment; import org.dynmap.Client; import org.dynmap.Color; import org.dynmap.ColorScheme; +import org.dynmap.ConfigurationNode; import org.dynmap.DynmapChunk; import org.dynmap.MapManager; import org.dynmap.MapTile; @@ -25,7 +26,7 @@ public class FlatMap extends MapType { private ColorScheme colorScheme; private int maximumHeight = 127; - public FlatMap(Map configuration) { + public FlatMap(ConfigurationNode configuration) { prefix = (String) configuration.get("prefix"); colorScheme = ColorScheme.getScheme((String) configuration.get("colorscheme")); Object o = configuration.get("maximumheight"); diff --git a/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java b/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java index 80b3fdc1..7d6d00dc 100644 --- a/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java @@ -4,10 +4,11 @@ import java.util.Map; import org.bukkit.World; import org.dynmap.Color; +import org.dynmap.ConfigurationNode; public class CaveTileRenderer extends DefaultTileRenderer { - public CaveTileRenderer(Map configuration) { + public CaveTileRenderer(ConfigurationNode configuration) { super(configuration); } diff --git a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java index 5c2cbe4c..5a9896a0 100644 --- a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java @@ -16,6 +16,7 @@ import org.bukkit.World.Environment; import org.dynmap.Client; import org.dynmap.Color; import org.dynmap.ColorScheme; +import org.dynmap.ConfigurationNode; import org.dynmap.MapManager; import org.dynmap.debug.Debug; @@ -33,7 +34,7 @@ public class DefaultTileRenderer implements MapTileRenderer { return name; } - public DefaultTileRenderer(Map configuration) { + public DefaultTileRenderer(ConfigurationNode configuration) { name = (String) configuration.get("prefix"); Object o = configuration.get("maximumheight"); if (o != null) { diff --git a/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java b/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java index c4e9567e..0c3318d1 100644 --- a/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java @@ -6,19 +6,16 @@ import java.util.Map; import org.bukkit.World; import org.dynmap.Color; +import org.dynmap.ConfigurationNode; public class HighlightTileRenderer extends DefaultTileRenderer { protected HashSet highlightBlocks = new HashSet(); - public HighlightTileRenderer(Map configuration) { + public HighlightTileRenderer(ConfigurationNode configuration) { super(configuration); - Object highlightObj = configuration.get("highlight"); - if (highlightObj instanceof List) { - for(Object o : (List)highlightObj) { - highlightBlocks.add((Integer)o); - } - } else if (highlightObj instanceof Integer) { - highlightBlocks.add((Integer)highlightObj); + List highlight = configuration.getList("highlight"); + for(Integer i : highlight) { + highlightBlocks.add(i); } } diff --git a/src/main/java/org/dynmap/kzedmap/KzedMap.java b/src/main/java/org/dynmap/kzedmap/KzedMap.java index f963c703..e42a34d7 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMap.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMap.java @@ -9,7 +9,9 @@ import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.World; +import org.dynmap.ConfigurationNode; import org.dynmap.DynmapChunk; +import org.dynmap.MapManager; import org.dynmap.MapTile; import org.dynmap.MapType; import org.dynmap.debug.Debug; @@ -37,34 +39,16 @@ public class KzedMap extends MapType { MapTileRenderer[] renderers; ZoomedTileRenderer zoomrenderer; - public KzedMap(Map configuration) { - renderers = loadRenderers(configuration); + public KzedMap(ConfigurationNode configuration) { + log.info(LOG_PREFIX + "Loading renderers for map '" + getClass().toString() + "'..."); + List renderers = configuration.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() + "'."); + zoomrenderer = new ZoomedTileRenderer(configuration); } - private MapTileRenderer[] loadRenderers(Map configuration) { - List configuredRenderers = (List) configuration.get("renderers"); - ArrayList renderers = new ArrayList(); - for (Object configuredRendererObj : configuredRenderers) { - try { - @SuppressWarnings("unchecked") - Map configuredRenderer = (Map) 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 public MapTile[] getTiles(Location l) { World world = l.getWorld(); diff --git a/src/main/java/org/dynmap/web/Json.java b/src/main/java/org/dynmap/web/Json.java index 882b00fb..05284cfd 100644 --- a/src/main/java/org/dynmap/web/Json.java +++ b/src/main/java/org/dynmap/web/Json.java @@ -23,8 +23,8 @@ public class Json { s.append("\"" + ((String)o).replace("\"", "\\\"") + "\""); } else if (o instanceof Integer || o instanceof Long || o instanceof Float || o instanceof Double) { s.append(o.toString()); - } else if (o instanceof LinkedHashMap) { - LinkedHashMap m = (LinkedHashMap) o; + } else if (o instanceof Map) { + Map m = (Map) o; s.append("{"); boolean first = true; for (Map.Entry entry : m.entrySet()) {