From 08f1b8726758e5459dff091884c8b99359d42869 Mon Sep 17 00:00:00 2001 From: Foorcee Date: Sun, 10 Oct 2021 02:32:04 +0200 Subject: [PATCH] Redirect player without message (#581) --- .../api/event/player/KickedFromServerEvent.java | 13 +++++++++++-- .../proxy/connection/client/ConnectedPlayer.java | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index ab0d912b6..eed14a0c6 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -130,8 +130,7 @@ public final class KickedFromServerEvent implements } /** - * Tells the proxy to redirect the player to another server. No messages will be sent from the - * proxy when this result is used. + * Tells the proxy to redirect the player to another server. */ public static final class RedirectPlayer implements ServerKickResult { @@ -159,8 +158,11 @@ public final class KickedFromServerEvent implements /** * Creates a new redirect result to forward the player to the specified {@code server}. + * The specified {@code message} will be sent to the player after the redirection. + * Use {@code Component.empty()} to skip sending any messages to the player. * * @param server the server to send the player to + * @param message the message will be sent to the player after redirecting * @return the redirect result */ public static RedirectPlayer create(RegisteredServer server, @@ -168,6 +170,13 @@ public final class KickedFromServerEvent implements return new RedirectPlayer(server, message); } + /** + * Creates a new redirect result to forward the player to the specified {@code server}. + * The kick reason will be displayed to the player + * + * @param server the server to send the player to + * @return the redirect result + */ public static ServerKickResult create(RegisteredServer server) { return new RedirectPlayer(server, null); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 46debee5e..e975afd73 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -641,7 +641,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (requestedMessage == null) { requestedMessage = friendlyReason; } - sendMessage(requestedMessage); + if (requestedMessage != Component.empty()) { + sendMessage(requestedMessage); + } break; default: // The only remaining value is successful (no need to do anything!)