13
0
geforkt von Mirrors/Velocity

Add ServerPostConnectEvent as a less confusing (and non-blocking) alternative to ServerConnectedEvent

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-07-12 16:13:04 -04:00
Ursprung f841d7590a
Commit 4c3d9de5fe
2 geänderte Dateien mit 42 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,39 @@
package com.velocitypowered.api.event.player;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Fired after the player has connected to a server. The server the player is now connected to is
* available in {@link Player#getCurrentServer()}.
*/
@Beta
public class ServerPostConnectEvent {
private final Player player;
private final RegisteredServer previousServer;
public ServerPostConnectEvent(Player player,
@Nullable RegisteredServer previousServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.previousServer = previousServer;
}
public Player getPlayer() {
return player;
}
public @Nullable RegisteredServer getPreviousServer() {
return previousServer;
}
@Override
public String toString() {
return "ServerPostConnectEvent{"
+ "player=" + player
+ ", previousServer=" + previousServer
+ '}';
}
}

Datei anzeigen

@ -4,6 +4,7 @@ import static com.velocitypowered.proxy.connection.backend.BackendConnectionPhas
import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO;
import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.ConnectionTypes;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
@ -113,6 +114,8 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
serverConn.getPlayer().setConnectedServer(serverConn); serverConn.getPlayer().setConnectedServer(serverConn);
// We're done! :) // We're done! :)
server.getEventManager().fireAndForget(new ServerPostConnectEvent(serverConn.getPlayer(),
existingConnection == null ? null : existingConnection.getServer()));
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
}, smc.eventLoop()) }, smc.eventLoop())
.exceptionally(exc -> { .exceptionally(exc -> {