package net.minecraft.network.protocol.status;

import com.google.gson.TypeAdapterFactory;
import net.minecraft.util.LowerCaseEnumTypeAdapterFactory;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.Component;
import java.lang.reflect.Type;
import com.google.gson.GsonBuilder;
import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.util.GsonHelper;
import net.minecraft.network.FriendlyByteBuf;
import com.google.gson.Gson;
import net.minecraft.network.protocol.Packet;

public class ClientboundStatusResponsePacket implements Packet<ClientStatusPacketListener> {
    private static final Gson GSON;
    private ServerStatus status;
    
    public ClientboundStatusResponsePacket() {
    }
    
    public ClientboundStatusResponsePacket(final ServerStatus tl) {
        this.status = tl;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.status = GsonHelper.<ServerStatus>fromJson(ClientboundStatusResponsePacket.GSON, mg.readUtf(32767), ServerStatus.class);
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeUtf(ClientboundStatusResponsePacket.GSON.toJson(this.status));
    }
    
    @Override
    public void handle(final ClientStatusPacketListener ti) {
        ti.handleStatusResponse(this);
    }
    
    public ServerStatus getStatus() {
        return this.status;
    }
    
    static {
        GSON = new GsonBuilder().registerTypeAdapter(ServerStatus.Version.class, new ServerStatus.Version.Serializer()).registerTypeAdapter(ServerStatus.Players.class, new ServerStatus.Players.Serializer()).registerTypeAdapter(ServerStatus.class, new ServerStatus.Serializer()).registerTypeHierarchyAdapter(Component.class, new Component.Serializer()).registerTypeHierarchyAdapter(Style.class, new Style.Serializer()).registerTypeAdapterFactory(new LowerCaseEnumTypeAdapterFactory()).create();
    }
}
