From 728cd8304ad9fd61e80588e6fb45bcbe8416015d Mon Sep 17 00:00:00 2001 From: zeeZ Date: Wed, 18 May 2011 15:55:24 +0200 Subject: [PATCH] Option to output player health in json for later web usage. --- configuration.txt | 3 +++ src/main/java/org/dynmap/Client.java | 4 +++- src/main/java/org/dynmap/DynmapPlugin.java | 2 +- src/main/java/org/dynmap/JsonTimerTask.java | 3 ++- .../java/org/dynmap/web/handlers/ClientUpdateHandler.java | 7 +++++-- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/configuration.txt b/configuration.txt index 1f280341..b8bdd5f3 100644 --- a/configuration.txt +++ b/configuration.txt @@ -37,6 +37,9 @@ jsonfile: false # How often the json file gets written to(in seconds) jsonfile-interval: 1 +# Output player health for web usage +health-in-json: true + # Use timesliced fullrender - takes a bit longer, but much more polite for server timeslicerender: true diff --git a/src/main/java/org/dynmap/Client.java b/src/main/java/org/dynmap/Client.java index 0d00991e..5ada186e 100644 --- a/src/main/java/org/dynmap/Client.java +++ b/src/main/java/org/dynmap/Client.java @@ -17,13 +17,15 @@ public class Client { public String name; public String world; public double x, y, z; + public int health; - public Player(String name, String world, double x, double y, double z) { + public Player(String name, String world, double x, double y, double z, int health) { this.name = ChatColor.stripColor(name); this.world = world; this.x = x; this.y = y; this.z = z; + this.health = health; } } diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 16298564..ad8fd0ac 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -139,7 +139,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())); + webServer.handlers.put("/up/", new ClientUpdateHandler(mapManager, playerList, getServer(), configuration.getBoolean("health-in-json", false))); webServer.handlers.put("/up/configuration", new ClientConfigurationHandler(configuration.getNode("web"))); if (configuration.getNode("web").getBoolean("allowwebchat", false)) { diff --git a/src/main/java/org/dynmap/JsonTimerTask.java b/src/main/java/org/dynmap/JsonTimerTask.java index 71390526..77451d33 100644 --- a/src/main/java/org/dynmap/JsonTimerTask.java +++ b/src/main/java/org/dynmap/JsonTimerTask.java @@ -44,6 +44,7 @@ class JsonTimerTask extends TimerTask { long jsonInterval = configuration.getInteger("jsonfile-interval", 1) * 1000; long current = System.currentTimeMillis(); File outputFile; + boolean showHealth = configuration.getBoolean("health-in-json", false); //Handles Reading WebChat if (configuration.getNode("web").getBoolean("allowwebchat", false)) { @@ -98,7 +99,7 @@ class JsonTimerTask extends TimerTask { for (int i = 0; i < players.length; i++) { Player p = players[i]; Location pl = p.getLocation(); - update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ()); + update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ(), showHealth?p.getHealth():-1); } update.updates = mapManager.getWorldUpdates(world.getName(), current - (jsonInterval + 10000)); diff --git a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java index d123f1a8..7f15700e 100644 --- a/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java +++ b/src/main/java/org/dynmap/web/handlers/ClientUpdateHandler.java @@ -9,6 +9,7 @@ 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.Client; import org.dynmap.MapManager; import org.dynmap.PlayerList; @@ -23,11 +24,13 @@ public class ClientUpdateHandler implements HttpHandler { private MapManager mapManager; private PlayerList playerList; private Server server; + private boolean showHealth; - public ClientUpdateHandler(MapManager mapManager, PlayerList playerList, Server server) { + public ClientUpdateHandler(MapManager mapManager, PlayerList playerList, Server server, boolean showHealth) { this.mapManager = mapManager; this.playerList = playerList; this.server = server; + this.showHealth = showHealth; } Pattern updatePathPattern = Pattern.compile("world/([^/]+)/([0-9]*)"); @@ -73,7 +76,7 @@ public class ClientUpdateHandler implements HttpHandler { for(int i=0;i