mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-02 16:49:56 +01:00
Option to output player health in json for later web usage.
This commit is contained in:
parent
7937a64f06
commit
728cd8304a
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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));
|
||||
|
@ -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<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(worldName, since);
|
||||
|
Loading…
Reference in New Issue
Block a user