Added debugging to configuration. Disabled by default.

This commit is contained in:
FrozenCow 2011-02-19 15:25:31 +01:00
parent 791341f210
commit c53e6058be
6 changed files with 54 additions and 12 deletions

View File

@ -81,3 +81,8 @@ web:
# title: Cave # title: Cave
# name: cave # name: cave
# prefix: ct # prefix: ct
# Enables debugging.
#debuggers:
# - class: org.dynmap.debug.LogDebugger
# - class: org.dynmap.debug.BukkitPlayerDebugger

View File

@ -2,8 +2,10 @@ package org.dynmap;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -19,7 +21,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration; 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.LogDebugger; import org.dynmap.debug.LogDebugger;
import org.dynmap.kzedmap.MapTileRenderer;
import org.dynmap.web.HttpServer; import org.dynmap.web.HttpServer;
import org.dynmap.web.handlers.ClientConfigurationHandler; import org.dynmap.web.handlers.ClientConfigurationHandler;
import org.dynmap.web.handlers.ClientUpdateHandler; import org.dynmap.web.handlers.ClientUpdateHandler;
@ -57,11 +61,11 @@ public class DynmapPlugin extends JavaPlugin {
} }
public void onEnable() { public void onEnable() {
Debug.addDebugger(new LogDebugger());
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
configuration.load(); configuration.load();
loadDebuggers();
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
tilesDirectory.mkdirs(); tilesDirectory.mkdirs();
@ -145,4 +149,25 @@ public class DynmapPlugin extends JavaPlugin {
public File getFile(String path) { public File getFile(String path) {
return combinePaths(DynmapPlugin.dataRoot, 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;
}
}
}
}
} }

View File

@ -1,6 +1,7 @@
package org.dynmap.debug; package org.dynmap.debug;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,7 +19,7 @@ public class BukkitPlayerDebugger implements Debugger {
private String undebugCommand; private String undebugCommand;
private String prepend; private String prepend;
public BukkitPlayerDebugger(JavaPlugin plugin) { public BukkitPlayerDebugger(JavaPlugin plugin, Map<String, Object> configuration) {
this.plugin = plugin; this.plugin = plugin;
String name = "dynmap"; String name = "dynmap";

View File

@ -1,10 +1,9 @@
package org.dynmap.debug; package org.dynmap.debug;
import java.util.LinkedList; import java.util.ArrayList;
import java.util.List;
public class Debug { public class Debug {
private static List<Debugger> debuggers = new LinkedList<Debugger>(); private static ArrayList<Debugger> debuggers = new ArrayList<Debugger>();
public synchronized static void addDebugger(Debugger d) { public synchronized static void addDebugger(Debugger d) {
debuggers.add(d); debuggers.add(d);
@ -19,14 +18,14 @@ public class Debug {
} }
public synchronized static void debug(String message) { 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) { 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) { 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);
} }
} }

View File

@ -1,12 +1,18 @@
package org.dynmap.debug; package org.dynmap.debug;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
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");
private static String prepend = "dynmap: "; private static String prepend = "dynmap: ";
public LogDebugger(JavaPlugin plugin, Map<String, Object> configuration) {
}
@Override @Override
public void debug(String message) { public void debug(String message) {
log.info(prepend + message); log.info(prepend + message);

View File

@ -1,7 +1,13 @@
package org.dynmap.debug; package org.dynmap.debug;
import java.util.Map;
import org.bukkit.plugin.java.JavaPlugin;
public class NullDebugger implements Debugger { public class NullDebugger implements Debugger {
public static final NullDebugger instance = new NullDebugger(); public static final NullDebugger instance = new NullDebugger(null, null);
public NullDebugger(JavaPlugin plugin, Map<String, Object> configuration) {
}
public void debug(String message) { public void debug(String message) {
} }