package net.md_5.bungee.protocol.packet;

import io.netty.buffer.ByteBuf;

public class PacketC9PlayerListItem extends DefinedPacket
{

    private String username;
    private boolean online;
    private short ping;

    private PacketC9PlayerListItem()
    {
        super( 0xC9 );
    }

    public PacketC9PlayerListItem(String username, boolean online, short ping)
    {
        super( 0xC9 );
        this.username = username;
        this.online = online;
        this.ping = ping;
    }

    @Override
    public void read(ByteBuf buf)
    {
        username = readString( buf );
        online = buf.readBoolean();
        ping = buf.readShort();
    }

    @Override
    public void write(ByteBuf buf)
    {
        writeString( username, buf );
        buf.writeBoolean( online );
        buf.writeShort( ping );
    }

    @Override
    public void handle(AbstractPacketHandler handler) throws Exception
    {
        handler.handle( this );
    }

    public String getUsername() {
        return this.username;
    }

    public boolean isOnline() {
        return this.online;
    }

    public short getPing() {
        return this.ping;
    }

    @Override
    public String toString() {
        return "PacketC9PlayerListItem(username=" + this.getUsername() + ", online=" + this.isOnline() + ", ping=" + this.getPing() + ")";
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof PacketC9PlayerListItem)) {
            return false;
        }
        final PacketC9PlayerListItem other = (PacketC9PlayerListItem) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$username = this.getUsername();
        final Object other$username = other.getUsername();
        if (this$username == null) {
            if (other$username == null) {
                return this.isOnline() == other.isOnline() && this.getPing() == other.getPing();
            }
        } else if (this$username.equals(other$username)) {
            return this.isOnline() == other.isOnline() && this.getPing() == other.getPing();
        }
        return false;
    }

    public boolean canEqual(final Object other) {
        return other instanceof PacketC9PlayerListItem;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        final Object $username = this.getUsername();
        result = result * 31 + (($username == null) ? 0 : $username.hashCode());
        result = result * 31 + (this.isOnline() ? 1231 : 1237);
        result = result * 31 + this.getPing();
        return result;
    }
}
