From f423169449f19aa786d52243bf33bfbeae8fa39a Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 29 Oct 2018 19:25:51 -0400 Subject: [PATCH] Fix issues with server connections. --- .../api/event/player/KickedFromServerEvent.java | 14 ++++++++------ .../client/ClientPlaySessionHandler.java | 3 ++- .../proxy/connection/client/ConnectedPlayer.java | 6 +----- 3 files changed, 11 insertions(+), 12 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 4811c669f..22a411ec4 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 @@ -4,8 +4,10 @@ import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; import net.kyori.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Fired when a player is kicked from a server. You may either allow Velocity to kick the player @@ -16,15 +18,15 @@ public final class KickedFromServerEvent implements private final Player player; private final RegisteredServer server; - private final Component originalReason; + private final @Nullable Component originalReason; private final boolean duringServerConnect; private ServerKickResult result; - public KickedFromServerEvent(Player player, RegisteredServer server, Component originalReason, - boolean duringServerConnect, Component fancyReason) { + public KickedFromServerEvent(Player player, RegisteredServer server, + @Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) { this.player = Preconditions.checkNotNull(player, "player"); this.server = Preconditions.checkNotNull(server, "server"); - this.originalReason = Preconditions.checkNotNull(originalReason, "originalReason"); + this.originalReason = originalReason; this.duringServerConnect = duringServerConnect; this.result = new Notify(fancyReason); } @@ -47,8 +49,8 @@ public final class KickedFromServerEvent implements return server; } - public Component getOriginalReason() { - return originalReason; + public Optional getOriginalReason() { + return Optional.ofNullable(originalReason); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 1725b91af..84720131f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -324,7 +324,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { joinGame.getLevelType())); } - // Remove old boss bars. These don't get cleared when sending JoinGame so we need to track these. + // Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to + // track them. for (UUID serverBossBar : serverBossBars) { BossBar deletePacket = new BossBar(); deletePacket.setUuid(serverBossBar); 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 866cd8a72..a3950b0c4 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 @@ -350,11 +350,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } else { connection.closeWith(Disconnect.create(friendlyReason)); } - } else if (kickReason != null) { - // Already connected to the server being disconnected from. + } else { KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, !connectedServer.getServer().equals(rs), friendlyReason); - server.getEventManager().fire(originalEvent) .thenAcceptAsync(event -> { if (event.getResult() instanceof DisconnectPlayer) { @@ -375,8 +373,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { connection.closeWith(Disconnect.create(friendlyReason)); } }, connection.eventLoop()); - } else { - connection.closeWith(Disconnect.create(friendlyReason)); } }