From b094a1daec2f2fb0f5fc0d111880464862b0d98e Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 2 Nov 2024 05:20:45 +0800 Subject: [PATCH] Avoid unclear disconnect messages when e.g. key verification failed --- .../org/geysermc/floodgate/mod/data/ModDataHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mod/src/main/java/org/geysermc/floodgate/mod/data/ModDataHandler.java b/mod/src/main/java/org/geysermc/floodgate/mod/data/ModDataHandler.java index 30590df..eded69c 100644 --- a/mod/src/main/java/org/geysermc/floodgate/mod/data/ModDataHandler.java +++ b/mod/src/main/java/org/geysermc/floodgate/mod/data/ModDataHandler.java @@ -90,7 +90,13 @@ private boolean checkAndHandleLogin(Object packet) { if (packet instanceof ServerboundHelloPacket) { String kickMessage = getKickMessage(); if (kickMessage != null) { - networkManager.disconnect(Component.nullToEmpty(kickMessage)); + Component message = Component.nullToEmpty(kickMessage); + // If possible, disconnect using the "proper" packet listener; otherwise there's no proper disconnect message + if (networkManager.getPacketListener() instanceof ServerLoginPacketListenerImpl loginPacketListener) { + loginPacketListener.disconnect(message); + } else { + networkManager.disconnect(message); + } return true; }