diff --git a/build.xml b/build.xml index f8b5633f..a6cf4921 100644 --- a/build.xml +++ b/build.xml @@ -1,16 +1,11 @@ - - - + + + - - - - - @@ -19,38 +14,25 @@ - - + - + + + + - - - - - - - - - - - - - - - - + - \ No newline at end of file + diff --git a/src/DMFlatFileSource.java b/src/DMFlatFileSource.java index 9eb96eea..c7b5cd62 100644 --- a/src/DMFlatFileSource.java +++ b/src/DMFlatFileSource.java @@ -2,12 +2,12 @@ import java.util.List; -public class DMFlatFileSource extends FlatFileSource { +public class DMFlatFileSource{/* extends FlatFileSource { public List getAllWarps() { return this.warps; } public List getAllHomes() { return this.homes; - } + }*/ } diff --git a/src/DMMySQLSource.java b/src/DMMySQLSource.java index 86b9780f..d535117a 100644 --- a/src/DMMySQLSource.java +++ b/src/DMMySQLSource.java @@ -2,12 +2,12 @@ import java.util.List; -public class DMMySQLSource extends MySQLSource { +public class DMMySQLSource{/* extends MySQLSource { public List getAllWarps() { return this.warps; } public List getAllHomes() { return this.homes; - } + }*/ } diff --git a/src/MapListener.java b/src/MapListener.java index 6e82e334..880df71f 100644 --- a/src/MapListener.java +++ b/src/MapListener.java @@ -2,8 +2,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.logging.Logger; +import org.bukkit.*; +import org.bukkit.event.block.*; -public class MapListener extends PluginListener { +public class MapListener extends BlockListener { private static final Logger log = Logger.getLogger("Minecraft"); private MapManager mgr; @@ -12,6 +14,14 @@ public class MapListener extends PluginListener { this.mgr = mgr; } + @Override + public void onBlockPlaced(BlockPlacedEvent event) { + Block blockPlaced = event.getBlock(); + if(mgr.touch(blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ())) + mgr.debug(/*player.getName() + */" touch " + blockPlaced.getX() + "," + blockPlaced.getY() + "," + blockPlaced.getZ() + " from onBlockCreate"); + } + +/* @Override public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, int itemInHand) { @@ -147,5 +157,5 @@ public class MapListener extends PluginListener { } return false; - } + }*/ } diff --git a/src/MapManager.java b/src/MapManager.java index 3b8228da..b78c818e 100644 --- a/src/MapManager.java +++ b/src/MapManager.java @@ -30,11 +30,15 @@ import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; +import org.bukkit.*; + import javax.imageio.ImageIO; public class MapManager extends Thread { protected static final Logger log = Logger.getLogger("Minecraft"); + public map etc; + /* dimensions of a map tile */ public static final int tileWidth = 128; public static final int tileHeight = 128; @@ -93,7 +97,7 @@ public class MapManager extends Thread { public String debugPlayer = null; /* hashmap of signs */ - public HashMap signs = null; + //public HashMap signs = null; /* cache this many zoomed-out tiles */ public static final int zoomCacheSize = 64; @@ -121,13 +125,14 @@ public class MapManager extends Thread { Server s = etc.getServer(); Player p = s.getPlayer(debugPlayer); if(p == null) return; - p.sendMessage("Map> " + Colors.Red + msg); + p.sendMessage("Map> " + Color.RED + msg); } - public MapManager() + public MapManager(map plugin) { + etc = plugin; /* load configuration */ - PropertiesFile properties; + /*PropertiesFile properties; properties = new PropertiesFile("server.properties"); try { @@ -140,7 +145,21 @@ public class MapManager extends Thread { generatePortraits = !properties.getString("map-generateportraits", "0").equals("0"); } catch(Exception ex) { log.log(Level.SEVERE, "Exception while reading properties for dynamic map", ex); + }*/ + tilepath = "/srv/http/dynmap/tiles/"; + colorsetpath = "colors.txt"; + signspath = "signs.txt"; + serverport = 8123; + datasource = "flatfile"; + showmarkers = "all"; + { + showSpawn = true; + showHomes = true; + showWarps = true; + showSigns = true; + showPlayers = true; } + generatePortraits = false; tileStore = new HashMap(); staleTiles = new LinkedList(); @@ -149,9 +168,9 @@ public class MapManager extends Thread { caveTileUpdates = new LinkedList(); zoomCache = new Cache(zoomCacheSize); - signs = new HashMap(); +// signs = new HashMap(); - loadShowOptions(); +// loadShowOptions(); } /* tile X for position x */ @@ -199,7 +218,7 @@ public class MapManager extends Thread { /* load colorset */ File cfile = new File(colorsetpath); - loadSigns(); + //loadSigns(); try { Scanner scanner = new Scanner(cfile); @@ -442,7 +461,7 @@ public class MapManager extends Thread { if(t == null) { /* no maptile exists, need to create one */ - t = new MapTile(px, py, ztilex(px), ztiley(py)); + t = new MapTile(etc, px, py, ztilex(px), ztiley(py)); tileStore.put(key, t); return t; } else { @@ -485,11 +504,12 @@ public class MapManager extends Thread { open.add(first); Server s = etc.getServer(); + World w = etc.getWorld(); while(open.size() > 0) { MapTile t = open.remove(open.size() - 1); if(t.stale) continue; - int h = s.getHighestBlockY(t.mx, t.mz); + int h = w.getHighestBlockYAt(t.mx, t.mz); log.info("walking: " + t.mx + ", " + t.mz + ", h = " + h); if(h < 1) @@ -651,7 +671,7 @@ public class MapManager extends Thread { } /* adds a sign to the map */ - public boolean addSign(Player player, String name, double px, double py, double pz) +/* public boolean addSign(Player player, String name, double px, double py, double pz) { if (signs.containsKey(name)) { @@ -675,10 +695,10 @@ public class MapManager extends Thread { } return false; - } + }*/ /* removes a sign from the map */ - public boolean removeSign(Player player, String name) +/* public boolean removeSign(Player player, String name) { if (signs.containsKey(name)) { @@ -702,10 +722,10 @@ public class MapManager extends Thread { } return false; - } + }*/ /* teleports a user to a sign */ - public boolean teleportToSign(Player player, String name) +/* public boolean teleportToSign(Player player, String name) { if (signs.containsKey(name)) { @@ -719,10 +739,10 @@ public class MapManager extends Thread { } return false; - } + }*/ /* load the map sign file */ - private void loadSigns() +/* private void loadSigns() { Scanner scanner = null; try @@ -779,10 +799,10 @@ public class MapManager extends Thread { { if (scanner != null) scanner.close(); } - } + }*/ /* save the map sign file */ - private void saveSigns() throws IOException +/* private void saveSigns() throws IOException { Writer out = null; try @@ -809,11 +829,11 @@ public class MapManager extends Thread { { if (out != null) out.close(); } - } + }*/ /* TODO: Is there a cleaner way to get warps/homes than using custom DataSource classes to expose the protected properties? */ - protected List loadWarps() +/* protected List loadWarps() { List warps = null; @@ -940,5 +960,5 @@ public class MapManager extends Thread { } return success; - } + }*/ } diff --git a/src/MapTile.java b/src/MapTile.java index ba389ae4..0aed150a 100644 --- a/src/MapTile.java +++ b/src/MapTile.java @@ -8,6 +8,8 @@ import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; +import org.bukkit.World; +import org.bukkit.Server; public class MapTile { protected static final Logger log = Logger.getLogger("Minecraft"); @@ -27,9 +29,11 @@ public class MapTile { /* whether the cave map of this tile needs to be updated */ boolean staleCave = false; + private map etc; /* create new MapTile */ - public MapTile(int px, int py, int zpx, int zpy) + public MapTile(map etc, int px, int py, int zpx, int zpy) { + this.etc = etc; this.px = px; this.py = py; this.zpx = zpx; @@ -51,17 +55,19 @@ public class MapTile { int x, z; Server s = etc.getServer(); + World w = etc.getWorld(); for(x=x1; x" + WebServer.VERSION; - sendHeader(out, code, "text/html", message.length(), System.currentTimeMillis()); - out.write(message.getBytes()); - out.flush(); - out.close(); - } - - public void run() - { - InputStream reader = null; - try { - sock.setSoTimeout(30000); - BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); - BufferedOutputStream out = new BufferedOutputStream(sock.getOutputStream()); - - String request = in.readLine(); - if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) { - // Invalid request type (no "GET") - sendError(out, 500, "Invalid Method."); - return; - } - - String path = request.substring(4, request.length() - 9); - - int current = (int) (System.currentTimeMillis() / 1000); - long cutoff = 0; - - if(path.charAt(0) == '/') { - try { - cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000; - } catch(NumberFormatException e) { - } - } - - sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis()); - - StringBuilder sb = new StringBuilder(); - sb.append(current + " " + etc.getServer().getRelativeTime() + "\n"); - - if (mgr.showPlayers) { - for(Player player : etc.getServer().getPlayerList()) { - sb.append(player.getName() + " player " + player.getX() + " " + player.getY() + " " + player.getZ() + "\n"); - } - } - - if (mgr.showSigns) { - for(Warp sign : mgr.signs.values()) - { - sb.append(sign.Name + " sign " + sign.Location.x + " " + sign.Location.y + " " + sign.Location.z + "\n"); - } - } - - if (mgr.showWarps) { - List warps = mgr.loadWarps(); - - if (warps != null) { - for(Warp warp : warps) { - sb.append(warp.Name + " warp " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); - } - } - } - - if (mgr.showHomes) { - List homes = mgr.loadHomes(); - - if (homes != null) { - for(Warp warp : homes) { - sb.append(warp.Name + " home " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); - } - } - } - - if (mgr.showSpawn) { - Location spawnLocation = etc.getServer().getSpawnLocation(); - - sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); - } - - synchronized(mgr.lock) { - for(TileUpdate tu : mgr.tileUpdates) { - if(tu.at >= cutoff) { - sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n"); - } - } - - for(TileUpdate tu : mgr.caveTileUpdates) { - if(tu.at >= cutoff) { - sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " c\n"); - } - } - } - - out.write(sb.toString().getBytes()); - - out.flush(); - out.close(); - } - catch (IOException e) { - if (reader != null) { - try { - reader.close(); - } - catch (Exception anye) { - // Do nothing. - } - } - } - } -} +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.Socket; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; +import org.bukkit.*; + +public class WebServerRequest extends Thread { + protected static final Logger log = Logger.getLogger("Minecraft"); + + private Socket sock; + private MapManager mgr; + private map etc; + + public WebServerRequest(Socket socket, MapManager mgr) + { + this.etc = mgr.etc; + sock = socket; + this.mgr = mgr; + } + + private static void sendHeader(BufferedOutputStream out, int code, String contentType, long contentLength, long lastModified) throws IOException + { + out.write(("HTTP/1.0 " + code + " OK\r\n" + + "Date: " + new Date().toString() + "\r\n" + + "Server: JibbleWebServer/1.0\r\n" + + "Content-Type: " + contentType + "\r\n" + + "Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n" + + ((contentLength != -1) ? "Content-Length: " + contentLength + "\r\n" : "") + + "Last-modified: " + new Date(lastModified).toString() + "\r\n" + + "\r\n").getBytes()); + } + + private static void sendError(BufferedOutputStream out, int code, String message) throws IOException + { + message = message + "
" + WebServer.VERSION; + sendHeader(out, code, "text/html", message.length(), System.currentTimeMillis()); + out.write(message.getBytes()); + out.flush(); + out.close(); + } + + public void run() + { + InputStream reader = null; + try { + sock.setSoTimeout(30000); + BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); + BufferedOutputStream out = new BufferedOutputStream(sock.getOutputStream()); + + String request = in.readLine(); + if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) { + // Invalid request type (no "GET") + sendError(out, 500, "Invalid Method."); + return; + } + + String path = request.substring(4, request.length() - 9); + + int current = (int) (System.currentTimeMillis() / 1000); + long cutoff = 0; + + if(path.charAt(0) == '/') { + try { + cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000; + } catch(NumberFormatException e) { + } + } + + sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis()); + + StringBuilder sb = new StringBuilder(); + //sb.append(current + " " + etc.getServer().getRelativeTime() + "\n"); + sb.append(current + " " + 0 +"\n"); + + if (mgr.showPlayers) { + for(Player player : etc.getServer().getOnlinePlayers()) { + sb.append(player.getName() + " player " + player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ() + "\n"); + } + } + + /*if (mgr.showSigns) { + for(Warp sign : mgr.signs.values()) + { + sb.append(sign.Name + " sign " + sign.Location.getX() + " " + sign.Location.getY() + " " + sign.Location.getZ() + "\n"); + } + } + + if (mgr.showWarps) { + List warps = mgr.loadWarps(); + + if (warps != null) { + for(Warp warp : warps) { + sb.append(warp.Name + " warp " + warp.Location.getX() + " " + warp.Location.getY() + " " + warp.Location.getZ() + "\n"); + } + } + } + + if (mgr.showHomes) { + List homes = mgr.loadHomes(); + + if (homes != null) { + for(Warp warp : homes) { + sb.append(warp.Name + " home " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + } + } + } + + if (mgr.showSpawn) { + Location spawnLocation = etc.getServer().getSpawnLocation(); + + sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); + }*/ + + synchronized(mgr.lock) { + for(TileUpdate tu : mgr.tileUpdates) { + if(tu.at >= cutoff) { + sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n"); + } + } + + for(TileUpdate tu : mgr.caveTileUpdates) { + if(tu.at >= cutoff) { + sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " c\n"); + } + } + } + + out.write(sb.toString().getBytes()); + + out.flush(); + out.close(); + } + catch (IOException e) { + if (reader != null) { + try { + reader.close(); + } + catch (Exception anye) { + // Do nothing. + } + } + } + } +} diff --git a/src/map.java b/src/map.java index f8d6cdce..719f8db7 100644 --- a/src/map.java +++ b/src/map.java @@ -1,7 +1,14 @@ import java.util.logging.Logger; import java.io.IOException; -public class map extends Plugin { +import java.io.File; +import org.bukkit.*; +import org.bukkit.event.*; +import org.bukkit.event.Event.Priority; +import org.bukkit.plugin.*; +import org.bukkit.plugin.java.*; + +public class map extends JavaPlugin { protected static final Logger log = Logger.getLogger("Minecraft"); @@ -9,11 +16,20 @@ public class map extends Plugin { private MapManager mgr = null; private MapListener listener = null; + public map(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { + super(pluginLoader, instance, desc, plugin, cLoader); + registerEvents(); + } + + public World getWorld() { + return getServer().getWorlds()[0]; + } + @Override - public void enable() { + public void onEnable() { log.info("Map INIT"); - mgr = new MapManager(); + mgr = new MapManager(this); mgr.startManager(); try { @@ -26,7 +42,7 @@ public class map extends Plugin { } @Override - public void disable() { + public void onDisable() { log.info("Map UNINIT"); mgr.stopManager(); @@ -37,9 +53,10 @@ public class map extends Plugin { } } - @Override - public void initialize() { - etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM); + public void registerEvents() { + getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, listener, Priority.Normal, this); + //getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DESTROYED, listener, Priority.Normal, this); + /* etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM); @@ -52,6 +69,6 @@ public class map extends Plugin { etc.getInstance().addCommand("/addsign", " [name] - adds a named sign to the map"); etc.getInstance().addCommand("/removesign", " [name] - removes a named sign to the map"); etc.getInstance().addCommand("/listsigns", " - list all named signs"); - etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign"); + etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign");*/ } } diff --git a/web/tiles/readme.txt b/web/tiles/readme.txt index 347e5d9b..15db7330 100644 --- a/web/tiles/readme.txt +++ b/web/tiles/readme.txt @@ -1,3 +1,3 @@ -Set map.js tileUrl to this folder -Also set map-tilepath in server.properties to point to this folder. +Set map.js tileUrl to this folder +Also set map-tilepath in server.properties to point to this folder. New tile images will be generated here by the plugin \ No newline at end of file diff --git a/web/up/readme.txt b/web/up/readme.txt index dae41af2..03195a97 100644 --- a/web/up/readme.txt +++ b/web/up/readme.txt @@ -1,2 +1,2 @@ -default.aspx is not required for all installations. +default.aspx is not required for all installations. If you are running a windows server with IIS, it may help in your setup. \ No newline at end of file