| 1 | package net.minecraft.network;
|
| 2 |
|
| 3 | import com.google.gson.JsonArray;
|
| 4 | import com.google.gson.JsonDeserializationContext;
|
| 5 | import com.google.gson.JsonDeserializer;
|
| 6 | import com.google.gson.JsonElement;
|
| 7 | import com.google.gson.JsonObject;
|
| 8 | import com.google.gson.JsonParseException;
|
| 9 | import com.google.gson.JsonSerializationContext;
|
| 10 | import com.google.gson.JsonSerializer;
|
| 11 | import com.mojang.authlib.GameProfile;
|
| 12 | import java.lang.reflect.Type;
|
| 13 | import java.util.UUID;
|
| 14 | import net.minecraft.util.IChatComponent;
|
| 15 | import net.minecraft.util.JsonUtils;
|
| 16 |
|
| 17 | public class ServerStatusResponse
|
| 18 | {
|
| 19 | private IChatComponent serverMotd;
|
| 20 | private ServerStatusResponse.PlayerCountData playerCount;
|
| 21 | private ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersion;
|
| 22 | private String favicon;
|
| 23 |
|
| 24 | public IChatComponent getServerDescription()
|
| 25 | {
|
| 26 | return this.serverMotd;
|
| 27 | }
|
| 28 |
|
| 29 | public void setServerDescription(IChatComponent motd)
|
| 30 | {
|
| 31 | this.serverMotd = motd;
|
| 32 | }
|
| 33 |
|
| 34 | public ServerStatusResponse.PlayerCountData getPlayerCountData()
|
| 35 | {
|
| 36 | return this.playerCount;
|
| 37 | }
|
| 38 |
|
| 39 | public void setPlayerCountData(ServerStatusResponse.PlayerCountData countData)
|
| 40 | {
|
| 41 | this.playerCount = countData;
|
| 42 | }
|
| 43 |
|
| 44 | public ServerStatusResponse.MinecraftProtocolVersionIdentifier getProtocolVersionInfo()
|
| 45 | {
|
| 46 | return this.protocolVersion;
|
| 47 | }
|
| 48 |
|
| 49 | public void setProtocolVersionInfo(ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersionData)
|
| 50 | {
|
| 51 | this.protocolVersion = protocolVersionData;
|
| 52 | }
|
| 53 |
|
| 54 | public void setFavicon(String faviconBlob)
|
| 55 | {
|
| 56 | this.favicon = faviconBlob;
|
| 57 | }
|
| 58 |
|
| 59 | public String getFavicon()
|
| 60 | {
|
| 61 | return this.favicon;
|
| 62 | }
|
| 63 |
|
| 64 | public static class MinecraftProtocolVersionIdentifier
|
| 65 | {
|
| 66 | private final String name;
|
| 67 | private final int protocol;
|
| 68 |
|
| 69 | public MinecraftProtocolVersionIdentifier(String nameIn, int protocolIn)
|
| 70 | {
|
| 71 | this.name = nameIn;
|
| 72 | this.protocol = protocolIn;
|
| 73 | }
|
| 74 |
|
| 75 | public String getName()
|
| 76 | {
|
| 77 | return this.name;
|
| 78 | }
|
| 79 |
|
| 80 | public int getProtocol()
|
| 81 | {
|
| 82 | return this.protocol;
|
| 83 | }
|
| 84 |
|
| 85 | public static class Serializer implements JsonDeserializer<ServerStatusResponse.MinecraftProtocolVersionIdentifier>, JsonSerializer<ServerStatusResponse.MinecraftProtocolVersionIdentifier>
|
| 86 | {
|
| 87 | public ServerStatusResponse.MinecraftProtocolVersionIdentifier deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 88 | {
|
| 89 | JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "version");
|
| 90 | return new ServerStatusResponse.MinecraftProtocolVersionIdentifier(JsonUtils.getString(jsonobject, "name"), JsonUtils.getInt(jsonobject, "protocol"));
|
| 91 | }
|
| 92 |
|
| 93 | public JsonElement serialize(ServerStatusResponse.MinecraftProtocolVersionIdentifier p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
|
| 94 | {
|
| 95 | JsonObject jsonobject = new JsonObject();
|
| 96 | jsonobject.addProperty("name", p_serialize_1_.getName());
|
| 97 | jsonobject.addProperty("protocol", (Number)Integer.valueOf(p_serialize_1_.getProtocol()));
|
| 98 | return jsonobject;
|
| 99 | }
|
| 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | public static class PlayerCountData
|
| 104 | {
|
| 105 | private final int maxPlayers;
|
| 106 | private final int onlinePlayerCount;
|
| 107 | private GameProfile[] players;
|
| 108 |
|
| 109 | public PlayerCountData(int maxOnlinePlayers, int onlinePlayers)
|
| 110 | {
|
| 111 | this.maxPlayers = maxOnlinePlayers;
|
| 112 | this.onlinePlayerCount = onlinePlayers;
|
| 113 | }
|
| 114 |
|
| 115 | public int getMaxPlayers()
|
| 116 | {
|
| 117 | return this.maxPlayers;
|
| 118 | }
|
| 119 |
|
| 120 | public int getOnlinePlayerCount()
|
| 121 | {
|
| 122 | return this.onlinePlayerCount;
|
| 123 | }
|
| 124 |
|
| 125 | public GameProfile[] getPlayers()
|
| 126 | {
|
| 127 | return this.players;
|
| 128 | }
|
| 129 |
|
| 130 | public void setPlayers(GameProfile[] playersIn)
|
| 131 | {
|
| 132 | this.players = playersIn;
|
| 133 | }
|
| 134 |
|
| 135 | public static class Serializer implements JsonDeserializer<ServerStatusResponse.PlayerCountData>, JsonSerializer<ServerStatusResponse.PlayerCountData>
|
| 136 | {
|
| 137 | public ServerStatusResponse.PlayerCountData deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 138 | {
|
| 139 | JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players");
|
| 140 | ServerStatusResponse.PlayerCountData serverstatusresponse$playercountdata = new ServerStatusResponse.PlayerCountData(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online"));
|
| 141 |
|
| 142 | if (JsonUtils.isJsonArray(jsonobject, "sample"))
|
| 143 | {
|
| 144 | JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample");
|
| 145 |
|
| 146 | if (jsonarray.size() > 0)
|
| 147 | {
|
| 148 | GameProfile[] agameprofile = new GameProfile[jsonarray.size()];
|
| 149 |
|
| 150 | for (int i = 0; i < agameprofile.length; ++i)
|
| 151 | {
|
| 152 | JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]");
|
| 153 | String s = JsonUtils.getString(jsonobject1, "id");
|
| 154 | agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name"));
|
| 155 | }
|
| 156 |
|
| 157 | serverstatusresponse$playercountdata.setPlayers(agameprofile);
|
| 158 | }
|
| 159 | }
|
| 160 |
|
| 161 | return serverstatusresponse$playercountdata;
|
| 162 | }
|
| 163 |
|
| 164 | public JsonElement serialize(ServerStatusResponse.PlayerCountData p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
|
| 165 | {
|
| 166 | JsonObject jsonobject = new JsonObject();
|
| 167 | jsonobject.addProperty("max", (Number)Integer.valueOf(p_serialize_1_.getMaxPlayers()));
|
| 168 | jsonobject.addProperty("online", (Number)Integer.valueOf(p_serialize_1_.getOnlinePlayerCount()));
|
| 169 |
|
| 170 | if (p_serialize_1_.getPlayers() != null && p_serialize_1_.getPlayers().length > 0)
|
| 171 | {
|
| 172 | JsonArray jsonarray = new JsonArray();
|
| 173 |
|
| 174 | for (int i = 0; i < p_serialize_1_.getPlayers().length; ++i)
|
| 175 | {
|
| 176 | JsonObject jsonobject1 = new JsonObject();
|
| 177 | UUID uuid = p_serialize_1_.getPlayers()[i].getId();
|
| 178 | jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString());
|
| 179 | jsonobject1.addProperty("name", p_serialize_1_.getPlayers()[i].getName());
|
| 180 | jsonarray.add(jsonobject1);
|
| 181 | }
|
| 182 |
|
| 183 | jsonobject.add("sample", jsonarray);
|
| 184 | }
|
| 185 |
|
| 186 | return jsonobject;
|
| 187 | }
|
| 188 | }
|
| 189 | }
|
| 190 |
|
| 191 | public static class Serializer implements JsonDeserializer<ServerStatusResponse>, JsonSerializer<ServerStatusResponse>
|
| 192 | {
|
| 193 | public ServerStatusResponse deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 194 | {
|
| 195 | JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "status");
|
| 196 | ServerStatusResponse serverstatusresponse = new ServerStatusResponse();
|
| 197 |
|
| 198 | if (jsonobject.has("description"))
|
| 199 | {
|
| 200 | serverstatusresponse.setServerDescription((IChatComponent)p_deserialize_3_.deserialize(jsonobject.get("description"), IChatComponent.class));
|
| 201 | }
|
| 202 |
|
| 203 | if (jsonobject.has("players"))
|
| 204 | {
|
| 205 | serverstatusresponse.setPlayerCountData((ServerStatusResponse.PlayerCountData)p_deserialize_3_.deserialize(jsonobject.get("players"), ServerStatusResponse.PlayerCountData.class));
|
| 206 | }
|
| 207 |
|
| 208 | if (jsonobject.has("version"))
|
| 209 | {
|
| 210 | serverstatusresponse.setProtocolVersionInfo((ServerStatusResponse.MinecraftProtocolVersionIdentifier)p_deserialize_3_.deserialize(jsonobject.get("version"), ServerStatusResponse.MinecraftProtocolVersionIdentifier.class));
|
| 211 | }
|
| 212 |
|
| 213 | if (jsonobject.has("favicon"))
|
| 214 | {
|
| 215 | serverstatusresponse.setFavicon(JsonUtils.getString(jsonobject, "favicon"));
|
| 216 | }
|
| 217 |
|
| 218 | return serverstatusresponse;
|
| 219 | }
|
| 220 |
|
| 221 | public JsonElement serialize(ServerStatusResponse p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
|
| 222 | {
|
| 223 | JsonObject jsonobject = new JsonObject();
|
| 224 |
|
| 225 | if (p_serialize_1_.getServerDescription() != null)
|
| 226 | {
|
| 227 | jsonobject.add("description", p_serialize_3_.serialize(p_serialize_1_.getServerDescription()));
|
| 228 | }
|
| 229 |
|
| 230 | if (p_serialize_1_.getPlayerCountData() != null)
|
| 231 | {
|
| 232 | jsonobject.add("players", p_serialize_3_.serialize(p_serialize_1_.getPlayerCountData()));
|
| 233 | }
|
| 234 |
|
| 235 | if (p_serialize_1_.getProtocolVersionInfo() != null)
|
| 236 | {
|
| 237 | jsonobject.add("version", p_serialize_3_.serialize(p_serialize_1_.getProtocolVersionInfo()));
|
| 238 | }
|
| 239 |
|
| 240 | if (p_serialize_1_.getFavicon() != null)
|
| 241 | {
|
| 242 | jsonobject.addProperty("favicon", p_serialize_1_.getFavicon());
|
| 243 | }
|
| 244 |
|
| 245 | return jsonobject;
|
| 246 | }
|
| 247 | }
|
| 248 | }
|
| 249 |
|