| 1 | package net.minecraft.network.status.server;
|
| 2 |
|
| 3 | import com.google.gson.Gson;
|
| 4 | import com.google.gson.GsonBuilder;
|
| 5 | import java.io.IOException;
|
| 6 | import net.minecraft.network.Packet;
|
| 7 | import net.minecraft.network.PacketBuffer;
|
| 8 | import net.minecraft.network.ServerStatusResponse;
|
| 9 | import net.minecraft.network.status.INetHandlerStatusClient;
|
| 10 | import net.minecraft.util.ChatStyle;
|
| 11 | import net.minecraft.util.EnumTypeAdapterFactory;
|
| 12 | import net.minecraft.util.IChatComponent;
|
| 13 |
|
| 14 | public class S00PacketServerInfo implements Packet<INetHandlerStatusClient>
|
| 15 | {
|
| 16 | private static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(ServerStatusResponse.MinecraftProtocolVersionIdentifier.class, new ServerStatusResponse.MinecraftProtocolVersionIdentifier.Serializer()).registerTypeAdapter(ServerStatusResponse.PlayerCountData.class, new ServerStatusResponse.PlayerCountData.Serializer()).registerTypeAdapter(ServerStatusResponse.class, new ServerStatusResponse.Serializer()).registerTypeHierarchyAdapter(IChatComponent.class, new IChatComponent.Serializer()).registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()).registerTypeAdapterFactory(new EnumTypeAdapterFactory()).create();
|
| 17 | private ServerStatusResponse response;
|
| 18 |
|
| 19 | public S00PacketServerInfo()
|
| 20 | {
|
| 21 | }
|
| 22 |
|
| 23 | public S00PacketServerInfo(ServerStatusResponse responseIn)
|
| 24 | {
|
| 25 | this.response = responseIn;
|
| 26 | }
|
| 27 |
|
| 28 | /**
|
| 29 | * Reads the raw packet data from the data stream.
|
| 30 | */
|
| 31 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 32 | {
|
| 33 | this.response = (ServerStatusResponse)GSON.fromJson(buf.readStringFromBuffer(32767), ServerStatusResponse.class);
|
| 34 | }
|
| 35 |
|
| 36 | /**
|
| 37 | * Writes the raw packet data to the data stream.
|
| 38 | */
|
| 39 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 40 | {
|
| 41 | buf.writeString(GSON.toJson((Object)this.response));
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Passes this Packet on to the NetHandler for processing.
|
| 46 | */
|
| 47 | public void processPacket(INetHandlerStatusClient handler)
|
| 48 | {
|
| 49 | handler.handleServerInfo(this);
|
| 50 | }
|
| 51 |
|
| 52 | public ServerStatusResponse getResponse()
|
| 53 | {
|
| 54 | return this.response;
|
| 55 | }
|
| 56 | }
|
| 57 |
|