From 7c0a402ccadd01eed134a78334ce7f8aad222f93 Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Sat, 31 Aug 2019 17:07:38 +0200 Subject: [PATCH 1/5] Add previous server to ServerConnectedEvent --- .../api/event/player/ServerConnectedEvent.java | 11 ++++++++++- .../connection/backend/TransitionSessionHandler.java | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index 2cd5f3eaf..c38dc12c8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -3,6 +3,8 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +import org.checkerframework.checker.nullness.qual.Nullable; /** * This event is fired once the player has successfully connected to the target server and the @@ -12,10 +14,13 @@ public final class ServerConnectedEvent { private final Player player; private final RegisteredServer server; + private final @Nullable RegisteredServer previousServer; - public ServerConnectedEvent(Player player, RegisteredServer server) { + public ServerConnectedEvent(Player player, RegisteredServer server, + @Nullable RegisteredServer previousServer) { this.player = Preconditions.checkNotNull(player, "player"); this.server = Preconditions.checkNotNull(server, "server"); + this.previousServer = previousServer; } public Player getPlayer() { @@ -26,6 +31,10 @@ public final class ServerConnectedEvent { return server; } + public Optional getPreviousServer() { + return Optional.ofNullable(previousServer); + } + @Override public String toString() { return "ServerConnectedEvent{" diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 1c6a0b05b..c5eb9d8d6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -80,7 +80,8 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); server.getEventManager() - .fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer())) + .fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer(), + existingConnection != null ? existingConnection.getServer() : null)) .whenCompleteAsync((x, error) -> { // Strap on the ClientPlaySessionHandler if required. ClientPlaySessionHandler playHandler; From 802251d273ab375245e6be0a25e1eae11e89fadb Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Mon, 28 Oct 2019 20:49:11 +0100 Subject: [PATCH 2/5] Add previous server to toString method --- .../api/event/player/ServerConnectedEvent.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index c38dc12c8..661cd1480 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -37,9 +37,10 @@ public final class ServerConnectedEvent { @Override public String toString() { - return "ServerConnectedEvent{" - + "player=" + player - + ", server=" + server - + '}'; + return "ServerConnectedEvent{" + + "player=" + player + + ", server=" + server + + ", previousServer=" + previousServer + + '}'; } } From ad291803eaa117f284dcf8c637341fe49a3e97fc Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Mon, 28 Oct 2019 21:18:53 +0100 Subject: [PATCH 3/5] Add missing JavaDoc --- .../api/event/player/ServerConnectedEvent.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index 661cd1480..7a61883ca 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -16,6 +16,12 @@ public final class ServerConnectedEvent { private final RegisteredServer server; private final @Nullable RegisteredServer previousServer; + /** + * Constructs a ServerConnectedEvent. + * @param player the player that was connected + * @param server the server the player was connected to + * @param previousServer the server the player was previously connected to + */ public ServerConnectedEvent(Player player, RegisteredServer server, @Nullable RegisteredServer previousServer) { this.player = Preconditions.checkNotNull(player, "player"); @@ -37,10 +43,10 @@ public final class ServerConnectedEvent { @Override public String toString() { - return "ServerConnectedEvent{" + - "player=" + player + - ", server=" + server + - ", previousServer=" + previousServer + - '}'; + return "ServerConnectedEvent{" + + "player=" + player + + ", server=" + server + + ", previousServer=" + previousServer + + '}'; } } From 9498376bfa9c0ccff069fab99bb77b7cdf3904d2 Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Mon, 28 Oct 2019 21:23:28 +0100 Subject: [PATCH 4/5] Add missing info to constructor doc --- .../velocitypowered/api/event/player/ServerConnectedEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index 7a61883ca..b8c9cb4cb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -20,7 +20,7 @@ public final class ServerConnectedEvent { * Constructs a ServerConnectedEvent. * @param player the player that was connected * @param server the server the player was connected to - * @param previousServer the server the player was previously connected to + * @param previousServer the server the player was previously connected to, null if none */ public ServerConnectedEvent(Player player, RegisteredServer server, @Nullable RegisteredServer previousServer) { From bc8756f7151e7283694961930badb0a775012eca Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Thu, 31 Oct 2019 19:31:47 +0100 Subject: [PATCH 5/5] Readd old constructor --- .../api/event/player/ServerConnectedEvent.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index b8c9cb4cb..0609798c1 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -29,6 +29,11 @@ public final class ServerConnectedEvent { this.previousServer = previousServer; } + @Deprecated + public ServerConnectedEvent(Player player, RegisteredServer server) { + this(player, server, null); + } + public Player getPlayer() { return player; }