From 100f3e05908ad80a3f426c6e729d09d0440189c6 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 13 Feb 2011 01:19:47 +0100 Subject: [PATCH] Added multiworld update support along with client-side support. --- configuration.txt | 9 ++++ .../java/org/dynmap/DynmapPlayerListener.java | 2 +- src/main/java/org/dynmap/MapManager.java | 38 ++++++++++++-- src/main/java/org/dynmap/PlayerList.java | 16 ++++++ src/main/java/org/dynmap/UpdateQueue.java | 4 +- src/main/java/org/dynmap/kzedmap/KzedMap.java | 2 - .../web/handlers/ClientUpdateHandler.java | 22 +++++++-- web/map.js | 49 +++++++++++++++++-- 8 files changed, 124 insertions(+), 18 deletions(-) diff --git a/configuration.txt b/configuration.txt index 4c90e367..30e73264 100644 --- a/configuration.txt +++ b/configuration.txt @@ -47,3 +47,12 @@ web: - type: KzedMapType name: cavemap prefix: ct + + # The name of the world shown when opening Dynmap's page. + defaultworld: world + + # The worlds shown in the menu. + shownworlds: + - world + - nether + - world_bad diff --git a/src/main/java/org/dynmap/DynmapPlayerListener.java b/src/main/java/org/dynmap/DynmapPlayerListener.java index d54e2000..7eb9bbc3 100644 --- a/src/main/java/org/dynmap/DynmapPlayerListener.java +++ b/src/main/java/org/dynmap/DynmapPlayerListener.java @@ -66,6 +66,6 @@ public class DynmapPlayerListener extends PlayerListener { * Relevant event details */ public void onPlayerChat(PlayerChatEvent event) { - mgr.updateQueue.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage())); + mgr.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage())); } } \ No newline at end of file diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index ccfd0fb5..18d8f57d 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -21,14 +21,16 @@ public class MapManager { private MapType[] mapTypes; public AsynchronousQueue tileQueue; - public UpdateQueue updateQueue; + + public Map worldUpdateQueues = new HashMap(); + public ArrayList worlds = new ArrayList(); + public PlayerList playerList; /* lock for our data structures */ public static final Object lock = new Object(); public MapManager(ConfigurationNode configuration) { - this.updateQueue = new UpdateQueue(); this.tileQueue = new AsynchronousQueue(new Handler() { @Override public void handle(MapTile t) { @@ -81,7 +83,6 @@ public class MapManager { if (render(tile)) { found.remove(tile); rendered.add(tile); - updateQueue.pushUpdate(new Client.Tile(tile.getFilename())); for (MapTile adjTile : map.getAdjecentTiles(tile)) { if (!found.contains(adjTile) && !rendered.contains(adjTile)) { found.add(adjTile); @@ -157,7 +158,9 @@ public class MapManager { } public boolean render(MapTile tile) { - return tile.getMap().render(tile, getTileFile(tile)); + boolean result = tile.getMap().render(tile, getTileFile(tile)); + pushUpdate(tile.getWorld(), new Client.Tile(tile.getFilename())); + return result; } @@ -172,4 +175,31 @@ public class MapManager { } return new File(worldTileDirectory, tile.getFilename()); } + + public void pushUpdate(Object update) { + for(int i=0;i visiblePlayers = new ArrayList(); + Player[] onlinePlayers = server.getOnlinePlayers(); + for (int i = 0; i < onlinePlayers.length; i++) { + Player p = onlinePlayers[i]; + if (p.getWorld().getName().equals(worldName) && !hiddenPlayerNames.contains(p.getName())) { + visiblePlayers.add(p); + } + } + Player[] result = new Player[visiblePlayers.size()]; + visiblePlayers.toArray(result); + return result; + } + public Player[] getVisiblePlayers() { ArrayList visiblePlayers = new ArrayList(); Player[] onlinePlayers = server.getOnlinePlayers(); diff --git a/src/main/java/org/dynmap/UpdateQueue.java b/src/main/java/org/dynmap/UpdateQueue.java index bddcb098..24a35eb5 100644 --- a/src/main/java/org/dynmap/UpdateQueue.java +++ b/src/main/java/org/dynmap/UpdateQueue.java @@ -11,7 +11,7 @@ public class UpdateQueue { private static final int maxUpdateAge = 120000; - public void pushUpdate(Object obj) { + public synchronized void pushUpdate(Object obj) { long now = System.currentTimeMillis(); long deadline = now - maxUpdateAge; synchronized (lock) { @@ -27,7 +27,7 @@ public class UpdateQueue { private ArrayList tmpupdates = new ArrayList(); - public Object[] getUpdatedObjects(long since) { + public synchronized Object[] getUpdatedObjects(long since) { long now = System.currentTimeMillis(); long deadline = now - maxUpdateAge; Object[] updates; diff --git a/src/main/java/org/dynmap/kzedmap/KzedMap.java b/src/main/java/org/dynmap/kzedmap/KzedMap.java index 4807671f..ef6d2adb 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMap.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMap.java @@ -15,11 +15,9 @@ import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.World; import org.dynmap.DynmapChunk; -import org.dynmap.MapManager; import org.dynmap.MapTile; import org.dynmap.MapType; import org.dynmap.debug.Debug; -import org.dynmap.debug.Debugger; public class KzedMap extends MapType { protected static final Logger log = Logger.getLogger("Minecraft"); diff --git a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java index c814db9c..6a87f6fc 100644 --- a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java +++ b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java @@ -2,6 +2,9 @@ package org.dynmap.web.handlers; import java.io.BufferedOutputStream; import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.bukkit.World; import org.bukkit.entity.Player; @@ -24,14 +27,24 @@ public class ClientUpdateHandler implements HttpHandler { this.world = world; } + Pattern updatePathPattern = Pattern.compile("world/([a-zA-Z0-9_]+)/([0-9]*)"); @Override public void handle(String path, HttpRequest request, HttpResponse response) throws Exception { + + Matcher match = updatePathPattern.matcher(path); + + if (!match.matches()) + return; + + String worldName = match.group(1); + String timeKey = match.group(2); + long current = System.currentTimeMillis(); - long cutoff = 0; + long since = 0; if (path.length() > 0) { try { - cutoff = Long.parseLong(path); + since = Long.parseLong(timeKey); } catch (NumberFormatException e) { } } @@ -41,14 +54,15 @@ public class ClientUpdateHandler implements HttpHandler { update.servertime = world.getTime() % 24000; - Player[] players = playerList.getVisiblePlayers(); + Player[] players = playerList.getVisiblePlayers(worldName); update.players = new Client.Player[players.length]; for(int i=0;i') + .addClass('worldlist') + .appendTo(sidebar); + + $.each(me.options.shownworlds, function(index, name) { + var worldButton; + $('
') + .addClass('worldrow') + .append(worldButton = $('') + .addClass('worldbutton') + .addClass('world_' + name) + .attr({ + type: 'radio', + name: 'world', + value: name + }) + .attr('checked', me.options.defaultworld == name ? 'checked' : null) + ) + .append($('