diff --git a/configuration.txt b/configuration.txt index 4992d461..533cad7a 100644 --- a/configuration.txt +++ b/configuration.txt @@ -80,4 +80,9 @@ web: # - type: KzedMapType # title: Cave # name: cave - # prefix: ct \ No newline at end of file + # prefix: ct + +# Enables debugging. +#debuggers: +# - class: org.dynmap.debug.LogDebugger +# - class: org.dynmap.debug.BukkitPlayerDebugger \ No newline at end of file diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 7a5826f6..1e1295c6 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -2,8 +2,10 @@ package org.dynmap; import java.io.File; import java.io.IOException; +import java.lang.reflect.Constructor; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -19,7 +21,9 @@ 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; import org.dynmap.debug.LogDebugger; +import org.dynmap.kzedmap.MapTileRenderer; import org.dynmap.web.HttpServer; import org.dynmap.web.handlers.ClientConfigurationHandler; import org.dynmap.web.handlers.ClientUpdateHandler; @@ -57,10 +61,10 @@ public class DynmapPlugin extends JavaPlugin { } public void onEnable() { - Debug.addDebugger(new LogDebugger()); - configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); configuration.load(); + + loadDebuggers(); tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); tilesDirectory.mkdirs(); @@ -145,4 +149,25 @@ public class DynmapPlugin extends JavaPlugin { public File getFile(String path) { return combinePaths(DynmapPlugin.dataRoot, path); } + + protected void loadDebuggers() { + Object debuggersConfiguration = configuration.getProperty("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("Error loading debugger: " + e); + e.printStackTrace(); + continue; + } + + } + } + } } diff --git a/src/main/java/org/dynmap/debug/BukkitPlayerDebugger.java b/src/main/java/org/dynmap/debug/BukkitPlayerDebugger.java index 30c67553..49336a24 100644 --- a/src/main/java/org/dynmap/debug/BukkitPlayerDebugger.java +++ b/src/main/java/org/dynmap/debug/BukkitPlayerDebugger.java @@ -1,6 +1,7 @@ package org.dynmap.debug; import java.util.HashSet; +import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -18,7 +19,7 @@ public class BukkitPlayerDebugger implements Debugger { private String undebugCommand; private String prepend; - public BukkitPlayerDebugger(JavaPlugin plugin) { + public BukkitPlayerDebugger(JavaPlugin plugin, Map configuration) { this.plugin = plugin; String name = "dynmap"; diff --git a/src/main/java/org/dynmap/debug/Debug.java b/src/main/java/org/dynmap/debug/Debug.java index 5de813ad..727d268d 100644 --- a/src/main/java/org/dynmap/debug/Debug.java +++ b/src/main/java/org/dynmap/debug/Debug.java @@ -1,10 +1,9 @@ package org.dynmap.debug; -import java.util.LinkedList; -import java.util.List; +import java.util.ArrayList; public class Debug { - private static List debuggers = new LinkedList(); + private static ArrayList debuggers = new ArrayList(); public synchronized static void addDebugger(Debugger d) { debuggers.add(d); @@ -19,14 +18,14 @@ public class Debug { } public synchronized static void debug(String message) { - for(Debugger d : debuggers) d.debug(message); + for(int i = 0; i < debuggers.size(); i++) debuggers.get(i).debug(message); } public synchronized static void error(String message) { - for(Debugger d : debuggers) d.error(message); + for(int i = 0; i < debuggers.size(); i++) debuggers.get(i).error(message); } public synchronized static void error(String message, Throwable thrown) { - for(Debugger d : debuggers) d.error(message, thrown); + for(int i = 0; i < debuggers.size(); i++) debuggers.get(i).error(message, thrown); } } diff --git a/src/main/java/org/dynmap/debug/LogDebugger.java b/src/main/java/org/dynmap/debug/LogDebugger.java index aa57ae87..c52ecd85 100644 --- a/src/main/java/org/dynmap/debug/LogDebugger.java +++ b/src/main/java/org/dynmap/debug/LogDebugger.java @@ -1,12 +1,18 @@ package org.dynmap.debug; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import org.bukkit.plugin.java.JavaPlugin; + public class LogDebugger implements Debugger { protected static final Logger log = Logger.getLogger("Minecraft"); private static String prepend = "dynmap: "; + public LogDebugger(JavaPlugin plugin, Map configuration) { + } + @Override public void debug(String message) { log.info(prepend + message); diff --git a/src/main/java/org/dynmap/debug/NullDebugger.java b/src/main/java/org/dynmap/debug/NullDebugger.java index 2bae1663..c1222c54 100644 --- a/src/main/java/org/dynmap/debug/NullDebugger.java +++ b/src/main/java/org/dynmap/debug/NullDebugger.java @@ -1,8 +1,14 @@ package org.dynmap.debug; -public class NullDebugger implements Debugger { - public static final NullDebugger instance = new NullDebugger(); +import java.util.Map; +import org.bukkit.plugin.java.JavaPlugin; +public class NullDebugger implements Debugger { + public static final NullDebugger instance = new NullDebugger(null, null); + + public NullDebugger(JavaPlugin plugin, Map configuration) { + } + public void debug(String message) { }