Don't send/construct redundant kick messages

This commit is contained in:
md_5 2020-01-29 11:05:38 +11:00
parent e9ba95b9dc
commit 1dee049007

View File

@ -118,6 +118,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHED;
}
private boolean canSendKickMessage()
{
return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHED;
}
@Override
public void connected(ChannelWrapper channel) throws Exception
{
@ -126,8 +131,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public void exception(Throwable t) throws Exception
{
if ( canSendKickMessage() )
{
disconnect( ChatColor.RED + Util.exception( t ) );
} else
{
ch.close();
}
}
@Override
@ -557,14 +568,20 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public void disconnect(String reason)
{
if ( canSendKickMessage() )
{
disconnect( TextComponent.fromLegacyText( reason ) );
} else
{
ch.close();
}
}
@Override
public void disconnect(final BaseComponent... reason)
{
if ( thisState != State.STATUS && thisState != State.PING && thisState != State.HANDSHAKE )
if ( canSendKickMessage() )
{
ch.delayedClose( new Kick( ComponentSerializer.toString( reason ) ) );
} else