Change server heartbeat's players section from an array to a dict

This commit is contained in:
Colin McDonald 2016-06-25 19:09:51 -04:00
parent a39a1801e4
commit 49a441fe03

View File

@ -38,7 +38,7 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
Server actorServer = ((ServerActor) actor).getServer();
ServerGroup actorServerGroup = ServerGroup.findById(actorServer.getServerGroup());
JsonObject requestBody = ctx.getBodyAsJson();
Map<UUID, String> playerNames = extractPlayerNames(requestBody.getJsonArray("players"));
Map<UUID, String> playerNames = extractPlayerNames(requestBody.getJsonObject("players"));
CompositeFuture.all(
createInfoResponse(actorServer, requestBody.getDouble("lastTps"), playerNames),
@ -156,18 +156,17 @@ public final class POSTServersHeartbeat implements Handler<RoutingContext> {
return callback;
}
private Map<UUID, String> extractPlayerNames(JsonArray players) {
private Map<UUID, String> extractPlayerNames(JsonObject players) {
Map<UUID, String> result = new HashMap<>();
for (Object player : players) {
JsonObject playerJson = (JsonObject) player;
UUID uuid = UUID.fromString(playerJson.getString("uuid"));
String username = playerJson.getString("username");
players.forEach((entry) -> {
UUID uuid = UUID.fromString(entry.getKey());
JsonObject data = (JsonObject) entry.getValue();
if (UuidUtils.isAcceptableUuid(uuid)) {
result.put(uuid, username);
}
result.put(uuid, data.getString("username"));
}
});
return result;
}