diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 879e5b53..7fa725ab 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -145,7 +145,7 @@ public class DynmapPlugin extends JavaPlugin { webServer = new HttpServer(bindAddress, port); webServer.handlers.put("/", new FilesystemHandler(getFile(configuration.getString("webpath", "web")))); webServer.handlers.put("/tiles/", new FilesystemHandler(tilesDirectory)); - webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer(), configuration.getBoolean("health-in-json", false))); + webServer.handlers.put("/up/", new ClientUpdateHandler(this, configuration.getBoolean("health-in-json", false))); webServer.handlers.put("/up/configuration", new ClientConfigurationHandler(this)); if (configuration.getBoolean("allowwebchat", false)) { diff --git a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java index b0cb2124..329336d3 100644 --- a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java +++ b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java @@ -11,6 +11,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.util.config.Configuration; import org.dynmap.Client; +import org.dynmap.DynmapPlugin; import org.dynmap.MapManager; import org.dynmap.PlayerList; import org.dynmap.web.HttpField; @@ -19,17 +20,16 @@ import org.dynmap.web.HttpRequest; import org.dynmap.web.HttpResponse; import org.dynmap.web.HttpStatus; import org.dynmap.web.Json; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import static org.dynmap.JSONUtils.*; public class ClientUpdateHandler implements HttpHandler { - private MapManager mapManager; - private PlayerList playerList; - private Server server; + private DynmapPlugin plugin; private boolean showHealth; - public ClientUpdateHandler(MapManager mapManager, PlayerList playerList, Server server, boolean showHealth) { - this.mapManager = mapManager; - this.playerList = playerList; - this.server = server; + public ClientUpdateHandler(DynmapPlugin plugin, boolean showHealth) { + this.plugin = plugin; this.showHealth = showHealth; } @@ -48,7 +48,7 @@ public class ClientUpdateHandler implements HttpHandler { String worldName = match.group(1); String timeKey = match.group(2); - World world = server.getWorld(worldName); + World world = plugin.getServer().getWorld(worldName); if (world == null) { response.status = WorldNotFound; return; @@ -64,26 +64,45 @@ public class ClientUpdateHandler implements HttpHandler { } } - Client.Update update = new Client.Update(); - update.timestamp = current; - update.servertime = world.getTime() % 24000; - update.hasStorm = world.hasStorm(); - update.isThundering = world.isThundering(); + JSONObject u = new JSONObject(); + //plugin.events.trigger("buildclientupdate", update); + s(u, "timestamp", current); + s(u, "servertime", world.getTime() % 24000); + s(u, "hasStorm", world.hasStorm()); + s(u, "isThundering", world.isThundering()); - - Player[] players = playerList.getVisiblePlayers(); - update.players = new Client.Player[players.length]; + s(u, "players", new JSONArray()); + Player[] players = plugin.playerList.getVisiblePlayers(); for(int i=0;i