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