package net.minecraft.network.protocol.handshake;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.SharedConstants;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.protocol.Packet;

public class ClientIntentionPacket implements Packet<ServerHandshakePacketListener> {
    private int protocolVersion;
    private String hostName;
    private int port;
    private ConnectionProtocol intention;
    
    public ClientIntentionPacket() {
    }
    
    public ClientIntentionPacket(final String string, final int integer, final ConnectionProtocol ku) {
        this.protocolVersion = SharedConstants.getCurrentVersion().getProtocolVersion();
        this.hostName = string;
        this.port = integer;
        this.intention = ku;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.protocolVersion = kv.readVarInt();
        this.hostName = kv.readUtf(255);
        this.port = kv.readUnsignedShort();
        this.intention = ConnectionProtocol.getById(kv.readVarInt());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.protocolVersion);
        kv.writeUtf(this.hostName);
        kv.writeShort(this.port);
        kv.writeVarInt(this.intention.getId());
    }
    
    @Override
    public void handle(final ServerHandshakePacketListener rf) {
        rf.handleIntention(this);
    }
    
    public ConnectionProtocol getIntention() {
        return this.intention;
    }
    
    public int getProtocolVersion() {
        return this.protocolVersion;
    }
}
