From 8537709045cbb20ca1c565626575d7499c5ffec4 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:40:39 +0100 Subject: [PATCH] Set disconnect BaseComponent on disconnect InitialHandler also optimze the exception handling of InitialHandler --- .../md_5/bungee/connection/InitialHandler.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index b1b087aa1..b06b033c7 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -110,6 +110,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Getter private String extraDataInHandshake = ""; private UserConnection userCon; + @Getter + private BaseComponent disconnectMessage; @Override public boolean shouldHandle(PacketWrapper packet) throws Exception @@ -137,13 +139,11 @@ 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(); - } + // if the connection is a login attempt, directly send a Kick with the Exception to the client + // we can't use disconnect() here as the method delays the Kick packet sending by 250ms and the HandlerBoss + // will close the channel before the packet is sent + // also we don't want to print the exception twice + ch.close( canSendKickMessage() ? new Kick( TextComponent.fromLegacy( ChatColor.RED + Util.exception( t ) ) ) : null ); } @Override @@ -666,7 +666,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( canSendKickMessage() ) { - ch.delayedClose( new Kick( reason ) ); + ch.delayedClose( new Kick( this.disconnectMessage = reason ) ); } else { ch.close();