3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Fix issues with server connections.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-10-29 19:25:51 -04:00
Ursprung 2b53d14461
Commit f423169449
3 geänderte Dateien mit 11 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -4,8 +4,10 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional;
import net.kyori.text.Component; import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull; 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 * 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 Player player;
private final RegisteredServer server; private final RegisteredServer server;
private final Component originalReason; private final @Nullable Component originalReason;
private final boolean duringServerConnect; private final boolean duringServerConnect;
private ServerKickResult result; private ServerKickResult result;
public KickedFromServerEvent(Player player, RegisteredServer server, Component originalReason, public KickedFromServerEvent(Player player, RegisteredServer server,
boolean duringServerConnect, Component fancyReason) { @Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) {
this.player = Preconditions.checkNotNull(player, "player"); this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server"); this.server = Preconditions.checkNotNull(server, "server");
this.originalReason = Preconditions.checkNotNull(originalReason, "originalReason"); this.originalReason = originalReason;
this.duringServerConnect = duringServerConnect; this.duringServerConnect = duringServerConnect;
this.result = new Notify(fancyReason); this.result = new Notify(fancyReason);
} }
@ -47,8 +49,8 @@ public final class KickedFromServerEvent implements
return server; return server;
} }
public Component getOriginalReason() { public Optional<Component> getOriginalReason() {
return originalReason; return Optional.ofNullable(originalReason);
} }
/** /**

Datei anzeigen

@ -324,7 +324,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
joinGame.getLevelType())); 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) { for (UUID serverBossBar : serverBossBars) {
BossBar deletePacket = new BossBar(); BossBar deletePacket = new BossBar();
deletePacket.setUuid(serverBossBar); deletePacket.setUuid(serverBossBar);

Datei anzeigen

@ -350,11 +350,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} else { } else {
connection.closeWith(Disconnect.create(friendlyReason)); connection.closeWith(Disconnect.create(friendlyReason));
} }
} else if (kickReason != null) { } else {
// Already connected to the server being disconnected from.
KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason,
!connectedServer.getServer().equals(rs), friendlyReason); !connectedServer.getServer().equals(rs), friendlyReason);
server.getEventManager().fire(originalEvent) server.getEventManager().fire(originalEvent)
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {
if (event.getResult() instanceof DisconnectPlayer) { if (event.getResult() instanceof DisconnectPlayer) {
@ -375,8 +373,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connection.closeWith(Disconnect.create(friendlyReason)); connection.closeWith(Disconnect.create(friendlyReason));
} }
}, connection.eventLoop()); }, connection.eventLoop());
} else {
connection.closeWith(Disconnect.create(friendlyReason));
} }
} }