13
0
geforkt von Mirrors/Velocity

Call DisconnectEvent explicitly instead of relying on ConnectedPlayer#teardown() to do it for us

Should fix (but not verified) #289
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-06-12 07:24:17 -04:00
Ursprung 669bd14779
Commit 8b8fd284b3
2 geänderte Dateien mit 20 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -104,6 +104,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null;
private boolean explicitlyDisconnected = false;
ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
@ -281,9 +282,20 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Override
public void disconnect(Component reason) {
if (connection.eventLoop().inEventLoop()) {
disconnect0(reason, false);
} else {
connection.eventLoop().execute(() -> disconnect0(reason, false));
}
}
public void disconnect0(Component reason, boolean duringLogin) {
logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacy().serialize(reason));
this.explicitlyDisconnected = true;
connection.closeWith(Disconnect.create(reason));
server.getEventManager().fireAndForget(new DisconnectEvent(this, duringLogin));
}
@Override
@ -574,10 +586,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connectedServer.disconnect();
}
boolean isConnected = server.getPlayer(this.getUniqueId()).isPresent();
server.unregisterConnection(this);
server.getEventManager().fire(new DisconnectEvent(this, !isConnected))
.thenRun(() -> this.teardownFuture.complete(null));
if (!this.explicitlyDisconnected) {
server.getEventManager().fire(new DisconnectEvent(this, !isConnected))
.thenRun(() -> this.teardownFuture.complete(null));
}
}
public CompletableFuture<Void> getTeardownFuture() {

Datei anzeigen

@ -204,7 +204,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
inbound.getVirtualHost().orElse(null), onlineMode);
this.connectedPlayer = player;
if (!server.canRegisterConnection(player)) {
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true);
return CompletableFuture.completedFuture(null);
}
@ -246,10 +246,10 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
Optional<Component> reason = event.getResult().getReason();
if (reason.isPresent()) {
player.disconnect(reason.get());
player.disconnect0(reason.get(), true);
} else {
if (!server.registerConnection(player)) {
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true);
return;
}
@ -269,7 +269,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
.thenRunAsync(() -> {
Optional<RegisteredServer> toTry = event.getInitialServer();
if (!toTry.isPresent()) {
player.disconnect(VelocityMessages.NO_AVAILABLE_SERVERS);
player.disconnect0(VelocityMessages.NO_AVAILABLE_SERVERS, true);
return;
}
player.createConnectionRequest(toTry.get()).fireAndForget();