Transfered client-updates to two components (jsonfile and internal).
This commit is contained in:
parent
9fa46597d1
commit
d5b4f6c8c4
11 changed files with 271 additions and 245 deletions
58
src/main/java/org/dynmap/ClientUpdateComponent.java
Normal file
58
src/main/java/org/dynmap/ClientUpdateComponent.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package org.dynmap;
|
||||
|
||||
import static org.dynmap.JSONUtils.a;
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ClientUpdateComponent extends Component {
|
||||
public ClientUpdateComponent(final DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||
super(plugin, configuration);
|
||||
plugin.events.addListener("buildclientupdate", new Event.Listener<ClientUpdateEvent>() {
|
||||
@Override
|
||||
public void triggered(ClientUpdateEvent e) {
|
||||
buildClientUpdate(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void buildClientUpdate(ClientUpdateEvent e) {
|
||||
World world = e.world.world;
|
||||
JSONObject u = e.update;
|
||||
long since = e.timestamp;
|
||||
String worldName = world.getName();
|
||||
|
||||
s(u, "servertime", world.getTime() % 24000);
|
||||
s(u, "hasStorm", world.hasStorm());
|
||||
s(u, "isThundering", world.isThundering());
|
||||
|
||||
s(u, "players", new JSONArray());
|
||||
Player[] players = plugin.playerList.getVisiblePlayers();
|
||||
for(int i=0;i<players.length;i++) {
|
||||
Player p = players[i];
|
||||
Location pl = p.getLocation();
|
||||
JSONObject jp = new JSONObject();
|
||||
s(jp, "type", "player");
|
||||
s(jp, "name", p.getDisplayName());
|
||||
s(jp, "account", p.getName());
|
||||
s(jp, "world", p.getWorld().getName());
|
||||
s(jp, "x", pl.getX());
|
||||
s(jp, "y", pl.getY());
|
||||
s(jp, "z", pl.getZ());
|
||||
if (configuration.getBoolean("sendhealth", false)) {
|
||||
s(jp, "health", p.getHealth());
|
||||
}
|
||||
a(u, "players", jp);
|
||||
}
|
||||
|
||||
s(u, "updates", new JSONArray());
|
||||
for(Object update : plugin.mapManager.getWorldUpdates(worldName, since)) {
|
||||
a(u, "updates", (Client.Update)update);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue