From 3aa48f2215fc6067949e0f3dbb15c3e17eb658d7 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 16 Jan 2011 18:09:58 +0100 Subject: [PATCH] Added configuration and renamed Map to MapType. --- build.xml | 5 ++++- src/main/java/org/dynmap/DynmapPlugin.java | 10 ++++++++-- src/main/java/org/dynmap/MapManager.java | 7 ++++--- src/main/java/org/dynmap/MapTile.java | 6 +++--- src/main/java/org/dynmap/{Map.java => MapType.java} | 4 ++-- src/main/java/org/dynmap/WebServer.java | 3 ++- .../java/org/dynmap/kzedmap/CaveTileRenderer.java | 5 +++-- .../org/dynmap/kzedmap/DefaultTileRenderer.java | 3 ++- src/main/java/org/dynmap/kzedmap/KzedMap.java | 13 +++++++------ .../java/org/dynmap/kzedmap/ZoomedTileRenderer.java | 3 ++- 10 files changed, 37 insertions(+), 22 deletions(-) rename src/main/java/org/dynmap/{Map.java => MapType.java} (85%) diff --git a/build.xml b/build.xml index 4a3fedc7..99b1efd3 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index d5ac0942..e557c45c 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -10,6 +10,7 @@ import org.bukkit.event.Event.Priority; import org.bukkit.event.block.BlockListener; import org.bukkit.plugin.*; import org.bukkit.plugin.java.*; +import org.bukkit.util.config.Configuration; import org.dynmap.debug.BukkitPlayerDebugger; public class DynmapPlugin extends JavaPlugin { @@ -30,12 +31,17 @@ public class DynmapPlugin extends JavaPlugin { } public void onEnable() { + if (!this.getDataFolder().isDirectory()) + this.getDataFolder().mkdirs(); + Configuration configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); + configuration.load(); + debugger.enable(); - mgr = new MapManager(getWorld(), debugger); + mgr = new MapManager(getWorld(), debugger, configuration); mgr.startManager(); try { - server = new WebServer(mgr.serverport, mgr, getServer(), debugger); + server = new WebServer(mgr.serverport, mgr, getServer(), debugger, configuration); } catch(IOException e) { log.info("position failed to start WebServer (IOException)"); } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index e4619d8a..2c67f0d8 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -5,6 +5,7 @@ import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debugger; import org.dynmap.kzedmap.KzedMap; @@ -13,7 +14,7 @@ public class MapManager extends Thread { private World world; private Debugger debugger; - private org.dynmap.Map map; + private MapType map; public StaleQueue staleQueue; /* lock for our data structures */ @@ -42,7 +43,7 @@ public class MapManager extends Thread { debugger.debug(msg); } - public MapManager(World world, Debugger debugger) + public MapManager(World world, Debugger debugger, ConfigurationNode configuration) { this.world = world; this.debugger = debugger; @@ -59,7 +60,7 @@ public class MapManager extends Thread { //webPath = "/srv/http/dynmap/"; webPath = "[JAR]"; - map = new KzedMap(this, world, debugger); + map = new KzedMap(this, world, debugger, configuration); } /* initialize and start map manager */ diff --git a/src/main/java/org/dynmap/MapTile.java b/src/main/java/org/dynmap/MapTile.java index 1d9dcb2a..529e821d 100644 --- a/src/main/java/org/dynmap/MapTile.java +++ b/src/main/java/org/dynmap/MapTile.java @@ -1,14 +1,14 @@ package org.dynmap; public abstract class MapTile { - private Map map; - public Map getMap() { + private MapType map; + public MapType getMap() { return map; } public abstract String getName(); - public MapTile(Map map) { + public MapTile(MapType map) { this.map = map; } } diff --git a/src/main/java/org/dynmap/Map.java b/src/main/java/org/dynmap/MapType.java similarity index 85% rename from src/main/java/org/dynmap/Map.java rename to src/main/java/org/dynmap/MapType.java index a976149e..eb01fa57 100644 --- a/src/main/java/org/dynmap/Map.java +++ b/src/main/java/org/dynmap/MapType.java @@ -4,7 +4,7 @@ import org.bukkit.Location; import org.bukkit.World; import org.dynmap.debug.Debugger; -public abstract class Map { +public abstract class MapType { private MapManager manager; public MapManager getMapManager() { return manager; @@ -20,7 +20,7 @@ public abstract class Map { return debugger; } - public Map(MapManager manager, World world, Debugger debugger) { + public MapType(MapManager manager, World world, Debugger debugger) { this.manager = manager; this.world = world; this.debugger = debugger; diff --git a/src/main/java/org/dynmap/WebServer.java b/src/main/java/org/dynmap/WebServer.java index 92b43956..07e08df6 100644 --- a/src/main/java/org/dynmap/WebServer.java +++ b/src/main/java/org/dynmap/WebServer.java @@ -7,6 +7,7 @@ import java.net.Socket; import java.util.logging.Logger; import org.bukkit.Server; +import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debugger; public class WebServer extends Thread { @@ -22,7 +23,7 @@ public class WebServer extends Thread { private MapManager mgr; private Server server; - public WebServer(int port, MapManager mgr, Server server, Debugger debugger) throws IOException + public WebServer(int port, MapManager mgr, Server server, Debugger debugger, ConfigurationNode configuration) throws IOException { this.mgr = mgr; this.server = server; diff --git a/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java b/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java index 68ef5e79..b20479db 100644 --- a/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/CaveTileRenderer.java @@ -3,12 +3,13 @@ package org.dynmap.kzedmap; import java.awt.Color; import org.bukkit.World; +import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debugger; public class CaveTileRenderer extends DefaultTileRenderer { - public CaveTileRenderer(String name, Debugger debugger) { - super(name, debugger); + public CaveTileRenderer(String name, Debugger debugger, ConfigurationNode configuration) { + super(name, debugger, configuration); } @Override diff --git a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java index ed646297..8b7d6ede 100644 --- a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java @@ -9,6 +9,7 @@ import java.io.IOException; import javax.imageio.ImageIO; import org.bukkit.World; +import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debugger; public class DefaultTileRenderer implements MapTileRenderer { @@ -19,7 +20,7 @@ public class DefaultTileRenderer implements MapTileRenderer { return name; } - public DefaultTileRenderer(String name, Debugger debugger) { + public DefaultTileRenderer(String name, Debugger debugger, ConfigurationNode configuration) { this.name = name; this.debugger = debugger; } diff --git a/src/main/java/org/dynmap/kzedmap/KzedMap.java b/src/main/java/org/dynmap/kzedmap/KzedMap.java index 2a10dd16..2bb202dc 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMap.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMap.java @@ -9,12 +9,13 @@ import java.util.Scanner; import org.bukkit.Location; import org.bukkit.World; -import org.dynmap.Map; +import org.bukkit.util.config.ConfigurationNode; +import org.dynmap.MapType; import org.dynmap.MapManager; import org.dynmap.MapTile; import org.dynmap.debug.Debugger; -public class KzedMap extends Map { +public class KzedMap extends MapType { /* dimensions of a map tile */ public static final int tileWidth = 128; public static final int tileHeight = 128; @@ -33,16 +34,16 @@ public class KzedMap extends Map { MapTileRenderer[] renderers; ZoomedTileRenderer zoomrenderer; - public KzedMap(MapManager manager, World world, Debugger debugger) { + public KzedMap(MapManager manager, World world, Debugger debugger, ConfigurationNode configuration) { super(manager, world, debugger); if (colors == null) { colors = loadColorSet("colors.txt"); } renderers = new MapTileRenderer[] { - new DefaultTileRenderer("t", debugger), - new CaveTileRenderer("ct", debugger), + new DefaultTileRenderer("t", debugger, configuration), + new CaveTileRenderer("ct", debugger, configuration), }; - zoomrenderer = new ZoomedTileRenderer(debugger); + zoomrenderer = new ZoomedTileRenderer(debugger, configuration); } @Override diff --git a/src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java b/src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java index 24e9e39d..261f65ba 100644 --- a/src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java @@ -8,12 +8,13 @@ import java.io.IOException; import javax.imageio.ImageIO; +import org.bukkit.util.config.ConfigurationNode; import org.dynmap.debug.Debugger; public class ZoomedTileRenderer { protected Debugger debugger; - public ZoomedTileRenderer(Debugger debugger) { + public ZoomedTileRenderer(Debugger debugger, ConfigurationNode configuration) { this.debugger = debugger; }