diff --git a/configuration.txt b/configuration.txt old mode 100644 new mode 100755 index a0bfceb0..dbe94f4f --- a/configuration.txt +++ b/configuration.txt @@ -15,6 +15,15 @@ webserver-bindaddress: 0.0.0.0 # The TCP-port the webserver will listen on. webserver-port: 8123 +# Disables Webserver portion of Dynmap (Advanced users only) +disable-webserver: false + +# Writes JSON to file in the webpath +jsonfile: false + +# How often the json file gets written to(in seconds) +jsonfile-interval: 1000 + # The maptypes Dynmap will use to render. worlds: - name: world @@ -36,12 +45,16 @@ worlds: maximumheight: 64 web: + # Handles the clientside updates differently only enable if using jsonfile + jsonfile: false + # Interval the browser should poll for updates. updaterate: 2000 # showchat: modal/balloons showchat: modal messagettl: 15000 + showplayerfacesonmap: true showplayerfacesinmenu: true focuschatballoons: false @@ -89,4 +102,4 @@ web: # Enables debugging. #debuggers: # - class: org.dynmap.debug.LogDebugger -# - class: org.dynmap.debug.BukkitPlayerDebugger \ No newline at end of file +# - class: org.dynmap.debug.BukkitPlayerDebugger diff --git a/src/main/java/org/dynmap/Client.java b/src/main/java/org/dynmap/Client.java index a0a2401b..e530006d 100644 --- a/src/main/java/org/dynmap/Client.java +++ b/src/main/java/org/dynmap/Client.java @@ -23,7 +23,11 @@ public class Client { } } - public static class ChatMessage { + public static class Stamped { + public long timestamp = System.currentTimeMillis(); + } + + public static class ChatMessage extends Stamped { public String type = "chat"; public String playerName; public String message; @@ -34,7 +38,7 @@ public class Client { } } - public static class WebChatMessage { + public static class WebChatMessage extends Stamped { public String type = "webchat"; public String playerName; public String message; @@ -45,7 +49,7 @@ public class Client { } } - public static class Tile { + public static class Tile extends Stamped { public String type = "tile"; public String name; diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 7d096ba7..bcbb4441 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -1,6 +1,8 @@ package org.dynmap; import java.io.File; +import java.io.FileOutputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Constructor; import java.net.InetAddress; @@ -8,6 +10,7 @@ import java.net.UnknownHostException; import java.util.List; import java.util.Map; import java.util.logging.Logger; +import java.util.Timer; import org.bukkit.Location; import org.bukkit.World; @@ -31,6 +34,7 @@ import org.dynmap.web.handlers.ClientUpdateHandler; import org.dynmap.web.handlers.FilesystemHandler; import org.dynmap.web.handlers.SendMessageHandler; import org.dynmap.web.handlers.SendMessageHandler.Message; +import org.dynmap.web.Json; public class DynmapPlugin extends JavaPlugin { @@ -41,6 +45,8 @@ public class DynmapPlugin extends JavaPlugin { public PlayerList playerList; public Configuration configuration; + public Timer timer; + public static File tilesDirectory; public World getWorld() { @@ -70,6 +76,19 @@ public class DynmapPlugin extends JavaPlugin { mapManager = new MapManager(this, configuration); mapManager.startRendering(); + loadWebserver(); + + if (configuration.getBoolean("jsonfile", false)) { + jsonConfig(); + int jsonInterval = configuration.getInt("jsonfile-interval", 1) * 1000; + timer = new Timer(); + timer.scheduleAtFixedRate(new JsonTimerTask(this, configuration), jsonInterval, jsonInterval); + } + + registerEvents(); + } + + public void loadWebserver() { InetAddress bindAddress; { String address = configuration.getString("webserver-bindaddress", "0.0.0.0"); @@ -105,8 +124,6 @@ public class DynmapPlugin extends JavaPlugin { } catch (IOException e) { log.severe("Failed to start WebServer on " + bindAddress + ":" + port + "!"); } - - registerEvents(); } public void onDisable() { @@ -116,6 +133,11 @@ public class DynmapPlugin extends JavaPlugin { webServer.shutdown(); webServer = null; } + + if (timer != null) { + timer.cancel(); + } + Debug.clearDebuggers(); } @@ -232,4 +254,24 @@ public class DynmapPlugin extends JavaPlugin { } return false; } + + private void jsonConfig() { + File outputFile; + Map clientConfig = (Map) configuration.getProperty("web"); + File webpath = new File(configuration.getString("webpath", "web"), "dynmap_config.json"); + if (webpath.isAbsolute()) + outputFile = webpath; + else + outputFile = new File(getDataFolder(), webpath.toString()); + + try { + FileOutputStream fos = new FileOutputStream(outputFile); + fos.write(Json.stringifyJson(clientConfig).getBytes()); + fos.close(); + } catch (FileNotFoundException ex) { + System.out.println("FileNotFoundException : " + ex); + } catch (IOException ioe) { + System.out.println("IOException : " + ioe); + } + } } diff --git a/src/main/java/org/dynmap/JsonTimerTask.java b/src/main/java/org/dynmap/JsonTimerTask.java new file mode 100644 index 00000000..1c355b0f --- /dev/null +++ b/src/main/java/org/dynmap/JsonTimerTask.java @@ -0,0 +1,66 @@ +package org.dynmap; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.TimerTask; + +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.config.Configuration; +import org.dynmap.web.Json; + +class JsonTimerTask extends TimerTask { + private final DynmapPlugin plugin; + private Server server; + private MapManager mapManager; + private Configuration configuration; + + public JsonTimerTask(DynmapPlugin instance, Configuration config) { + this.plugin = instance; + this.server = this.plugin.getServer(); + this.mapManager = this.plugin.getMapManager(); + this.configuration = config; + } + + public void run() { + for (World world : this.server.getWorlds()) { + long current = System.currentTimeMillis(); + + Client.Update update = new Client.Update(); + + update.timestamp = current; + update.servertime = world.getTime() % 24000; + + Player[] players = mapManager.playerList.getVisiblePlayers(); + update.players = new Client.Player[players.length]; + for (int i = 0; i < players.length; i++) { + Player p = players[i]; + Location pl = p.getLocation(); + update.players[i] = new Client.Player(p.getName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ()); + } + + update.updates = mapManager.getWorldUpdates(world.getName(), current - (configuration.getInt("jsonfile-interval", 1) + 10000)); + + File webpath = new File(this.configuration.getString("webpath", "web"), "dynmap_" + world.getName() + ".json"); + File outputFile; + if (webpath.isAbsolute()) + outputFile = webpath; + else { + outputFile = new File(plugin.getDataFolder(), webpath.toString()); + } + try { + FileOutputStream fos = new FileOutputStream(outputFile); + fos.write(Json.stringifyJson(update).getBytes()); + fos.close(); + } catch (FileNotFoundException ex) { + System.out.println("FileNotFoundException : " + ex); + } catch (IOException ioe) { + System.out.println("IOException : " + ioe); + } + } + } +} \ No newline at end of file diff --git a/web/map.js b/web/map.js index 6c1c7bb6..53d48bf0 100644 --- a/web/map.js +++ b/web/map.js @@ -103,7 +103,7 @@ DynMap.prototype = { }; google.maps.event.addListener(map, 'dragstart', function(mEvent) { - me.followPlayer(''); + me.followPlayer(null); }); // TODO: Enable hash-links. /*google.maps.event.addListener(map, 'zoom_changed', function() { @@ -277,7 +277,9 @@ DynMap.prototype = { $.getJSON(me.options.updateUrl + "world/" + me.world.name + "/" + me.lasttimestamp, function(update) { me.alertbox.hide(); - me.lasttimestamp = update.timestamp; + if (!me.options.jsonfile) + me.lasttimestamp = update.timestamp; + me.clock.setTime(update.servertime); me.clockdigital.setTime(update.servertime); @@ -303,19 +305,24 @@ DynMap.prototype = { $.each(update.updates, function(index, update) { swtch(update.type, { tile: function() { - me.onTileUpdated(update.name); + + if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + me.onTileUpdated(update.name); }, chat: function() { if (!me.options.showchat) { return; } - me.onPlayerChat(update.playerName, update.message); + if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + me.onPlayerChat(update.playerName, update.message); }, webchat: function() { if (!me.options.showchat) { return; } - me.onPlayerChat('[WEB]' + update.playerName, update.message); + + if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile) + me.onPlayerChat('[WEB]' + update.playerName, update.message); } }, function(type) { console.log('Unknown type ', type, '!'); @@ -325,7 +332,6 @@ DynMap.prototype = { //var divs = $('div[rel]'); //divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove(); }); - setTimeout(function() { me.update(); }, me.options.updaterate); }, function(request, statusText, ex) { me.alertbox @@ -575,4 +581,4 @@ DynMap.prototype = { + "&zoom=" + me.map.getZoom(); me.linkbox.data('link').val(a); }*/ -}; \ No newline at end of file +};