Server-side multiworld support with several improvements overal.

This commit is contained in:
FrozenCow 2011-02-12 23:45:33 +01:00
parent 2fd91ef94b
commit 5b0171c459
20 changed files with 398 additions and 296 deletions

View file

@ -17,7 +17,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import org.dynmap.debug.BukkitPlayerDebugger;
import org.dynmap.debug.Debug;
import org.dynmap.debug.LogDebugger;
import org.dynmap.web.HttpServer;
import org.dynmap.web.handlers.ClientConfigurationHandler;
import org.dynmap.web.handlers.ClientUpdateHandler;
@ -32,8 +33,7 @@ public class DynmapPlugin extends JavaPlugin {
private PlayerList playerList;
private Configuration configuration;
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
public static File tilesDirectory;
public static File dataRoot;
public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
@ -54,15 +54,18 @@ public class DynmapPlugin extends JavaPlugin {
}
public void onEnable() {
Debug.addDebugger(new LogDebugger());
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
configuration.load();
debugger.enable();
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
playerList = new PlayerList(getServer());
playerList.load();
mapManager = new MapManager(getWorld(), debugger, configuration);
mapManager.startManager();
mapManager = new MapManager(configuration);
mapManager.startRendering();
InetAddress bindAddress;
{
@ -78,8 +81,8 @@ public class DynmapPlugin extends JavaPlugin {
int port = configuration.getInt("webserver-port", 8123);
webServer = new HttpServer(bindAddress, port);
webServer.handlers.put("/", new FilesystemHandler(mapManager.webDirectory));
webServer.handlers.put("/tiles/", new FilesystemHandler(mapManager.tileDirectory));
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, getWorld()));
webServer.handlers.put("/up/configuration", new ClientConfigurationHandler((Map<?, ?>) configuration.getProperty("web")));
@ -93,13 +96,13 @@ public class DynmapPlugin extends JavaPlugin {
}
public void onDisable() {
mapManager.stopManager();
mapManager.stopRendering();
if (webServer != null) {
webServer.shutdown();
webServer = null;
}
debugger.disable();
Debug.clearDebuggers();
}
public void registerEvents() {
@ -111,4 +114,18 @@ public class DynmapPlugin extends JavaPlugin {
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
}
private static File combinePaths(File parent, String path) {
return combinePaths(parent, new File(path));
}
private static File combinePaths(File parent, File path) {
if (path.isAbsolute())
return path;
return new File(parent, path.getPath());
}
public File getFile(String path) {
return combinePaths(DynmapPlugin.dataRoot, path);
}
}