mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-27 20:58:40 +01:00
Added debugging to configuration. Disabled by default.
This commit is contained in:
parent
791341f210
commit
c53e6058be
@ -81,3 +81,8 @@ web:
|
||||
# title: Cave
|
||||
# name: cave
|
||||
# prefix: ct
|
||||
|
||||
# Enables debugging.
|
||||
#debuggers:
|
||||
# - class: org.dynmap.debug.LogDebugger
|
||||
# - class: org.dynmap.debug.BukkitPlayerDebugger
|
@ -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,11 +61,11 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Object> configuration) {
|
||||
this.plugin = plugin;
|
||||
|
||||
String name = "dynmap";
|
||||
|
@ -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<Debugger> debuggers = new LinkedList<Debugger>();
|
||||
private static ArrayList<Debugger> debuggers = new ArrayList<Debugger>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Object> configuration) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
log.info(prepend + message);
|
||||
|
@ -1,7 +1,13 @@
|
||||
package org.dynmap.debug;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
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) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user