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 mf) {
        this.protocolVersion = SharedConstants.getCurrentVersion().getProtocolVersion();
        this.hostName = string;
        this.port = integer;
        this.intention = mf;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.protocolVersion = mg.readVarInt();
        this.hostName = mg.readUtf(255);
        this.port = mg.readUnsignedShort();
        this.intention = ConnectionProtocol.getById(mg.readVarInt());
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.protocolVersion);
        mg.writeUtf(this.hostName);
        mg.writeShort(this.port);
        mg.writeVarInt(this.intention.getId());
    }
    
    @Override
    public void handle(final ServerHandshakePacketListener su) {
        su.handleIntention(this);
    }
    
    public ConnectionProtocol getIntention() {
        return this.intention;
    }
    
    public int getProtocolVersion() {
        return this.protocolVersion;
    }
}
