From edcf1cfd10b47f0eb6406e922509f5de67c27873 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Wed, 30 Nov 2011 12:31:15 +0800 Subject: [PATCH] Make web UI reload when configuration changes, server restarts --- .../org/dynmap/ClientConfigurationComponent.java | 1 + src/main/java/org/dynmap/ClientUpdateComponent.java | 4 +++- src/main/java/org/dynmap/DynmapPlugin.java | 12 ++++++++++++ web/js/map.js | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dynmap/ClientConfigurationComponent.java b/src/main/java/org/dynmap/ClientConfigurationComponent.java index 46389fcc..d885bc0e 100644 --- a/src/main/java/org/dynmap/ClientConfigurationComponent.java +++ b/src/main/java/org/dynmap/ClientConfigurationComponent.java @@ -14,6 +14,7 @@ public class ClientConfigurationComponent extends Component { @Override public void triggered(JSONObject t) { ConfigurationNode c = plugin.configuration; + s(t, "confighash", plugin.getConfigHashcode()); s(t, "updaterate", c.getFloat("updaterate", 1.0f)); s(t, "showplayerfacesinmenu", c.getBoolean("showplayerfacesinmenu", true)); s(t, "joinmessage", c.getString("joinmessage", "%playername% joined")); diff --git a/src/main/java/org/dynmap/ClientUpdateComponent.java b/src/main/java/org/dynmap/ClientUpdateComponent.java index 6cb702f9..84d013d0 100644 --- a/src/main/java/org/dynmap/ClientUpdateComponent.java +++ b/src/main/java/org/dynmap/ClientUpdateComponent.java @@ -35,7 +35,9 @@ public class ClientUpdateComponent extends Component { String worldName = world.getName(); int hideifshadow = configuration.getInteger("hideifshadow", 15); int hideifunder = configuration.getInteger("hideifundercover", 15); - + + s(u, "confighash", plugin.getConfigHashcode()); + s(u, "servertime", world.getTime() % 24000); s(u, "hasStorm", world.hasStorm()); s(u, "isThundering", world.isThundering()); diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 52ffc5e5..7f339c9b 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -81,6 +81,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { boolean waterbiomeshading = false; boolean fencejoin = false; public CompassMode compassmode = CompassMode.PRE19; + private int config_hashcode; /* Used to signal need to reload web configuration (world changes, config update, etc) */ public enum CompassMode { PRE19, /* Default for 1.8 and earlier (east is Z+) */ @@ -297,6 +298,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { playerfacemgr = new PlayerFaces(this); + updateConfigHashcode(); /* Initialize/update config hashcode */ + loadWebserver(); enabledTriggers.clear(); @@ -327,6 +330,14 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { events.trigger("initialized", null); } + public void updateConfigHashcode() { + config_hashcode = (int)System.currentTimeMillis(); + } + + public int getConfigHashcode() { + return config_hashcode; + } + public void loadWebserver() { InetAddress bindAddress; { @@ -633,6 +644,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { @Override public void onWorldLoad(WorldLoadEvent event) { mapManager.activateWorld(event.getWorld()); + updateConfigHashcode(); } }; diff --git a/web/js/map.js b/web/js/map.js index 592b0a35..f6471553 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -526,6 +526,10 @@ DynMap.prototype = { if (!me.options.jsonfile) { me.lasttimestamp = update.timestamp; } + if(me.options.confighash != update.confighash) { + window.location.reload(true); + return; + } me.servertime = update.servertime; var newserverday = (me.servertime > 23100 || me.servertime < 12900);