60 lines
2.0 KiB
Java
60 lines
2.0 KiB
Java
package com.mojang.realmsclient.dto;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
import java.util.Iterator;
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.common.collect.Lists;
|
|
import com.mojang.realmsclient.util.JsonUtils;
|
|
import com.google.gson.JsonObject;
|
|
import java.util.List;
|
|
import com.google.gson.JsonParser;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
public class RealmsServerPlayerList extends ValueObject {
|
|
private static final Logger LOGGER;
|
|
private static final JsonParser JSON_PARSER;
|
|
public long serverId;
|
|
public List<String> players;
|
|
|
|
public static RealmsServerPlayerList parse(final JsonObject jsonObject) {
|
|
final RealmsServerPlayerList dit2 = new RealmsServerPlayerList();
|
|
try {
|
|
dit2.serverId = JsonUtils.getLongOr("serverId", jsonObject, -1L);
|
|
final String string3 = JsonUtils.getStringOr("playerList", jsonObject, null);
|
|
if (string3 != null) {
|
|
final JsonElement jsonElement4 = RealmsServerPlayerList.JSON_PARSER.parse(string3);
|
|
if (jsonElement4.isJsonArray()) {
|
|
dit2.players = parsePlayers(jsonElement4.getAsJsonArray());
|
|
}
|
|
else {
|
|
dit2.players = Lists.newArrayList();
|
|
}
|
|
}
|
|
else {
|
|
dit2.players = Lists.newArrayList();
|
|
}
|
|
}
|
|
catch (Exception exception3) {
|
|
RealmsServerPlayerList.LOGGER.error("Could not parse RealmsServerPlayerList: " + exception3.getMessage());
|
|
}
|
|
return dit2;
|
|
}
|
|
|
|
private static List<String> parsePlayers(final JsonArray jsonArray) {
|
|
final List<String> list2 = Lists.newArrayList();
|
|
for (final JsonElement jsonElement4 : jsonArray) {
|
|
try {
|
|
list2.add(jsonElement4.getAsString());
|
|
}
|
|
catch (Exception ex) {}
|
|
}
|
|
return list2;
|
|
}
|
|
|
|
static {
|
|
LOGGER = LogManager.getLogger();
|
|
JSON_PARSER = new JsonParser();
|
|
}
|
|
}
|