From bd35c6835efb1d070f3b66a0064e7e89b8f0b778 Mon Sep 17 00:00:00 2001 From: james58899 Date: Mon, 14 Oct 2019 22:00:07 +0800 Subject: [PATCH] Allow set redirect message --- .../api/event/player/KickedFromServerEvent.java | 17 ++++++++++++++--- .../connection/client/ConnectedPlayer.java | 6 +++++- 2 files changed, 19 insertions(+), 4 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 87ae8c3f0..e08e1d741 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 @@ -147,10 +147,12 @@ public final class KickedFromServerEvent implements */ public static final class RedirectPlayer implements ServerKickResult { + private final Component message; private final RegisteredServer server; - private RedirectPlayer(RegisteredServer server) { + private RedirectPlayer(RegisteredServer server, @Nullable Component message) { this.server = Preconditions.checkNotNull(server, "server"); + this.message = message; } @Override @@ -162,14 +164,23 @@ public final class KickedFromServerEvent implements return server; } + @Nullable + public Component getMessage() { + return message; + } + /** * Creates a new redirect result to forward the player to the specified {@code server}. * * @param server the server to send the player to * @return the redirect result */ - public static RedirectPlayer create(RegisteredServer server) { - return new RedirectPlayer(server); + public static RedirectPlayer create(RegisteredServer server, @Nullable Component message) { + return new RedirectPlayer(server, message); + } + + public static ServerKickResult create(RegisteredServer server) { + return create(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 c012e8fcb..e7be50b36 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 @@ -463,7 +463,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (newResult == null || !newResult) { disconnect(friendlyReason); } else { - sendMessage(VelocityMessages.MOVED_TO_NEW_SERVER.append(friendlyReason)); + if (res.getMessage() == null) { + sendMessage(VelocityMessages.MOVED_TO_NEW_SERVER.append(friendlyReason)); + } else { + sendMessage(res.getMessage()); + } } }, connection.eventLoop()); } else if (event.getResult() instanceof Notify) {