geforkt von Mirrors/Velocity
Merge pull request #256 from Gabik21/previous-server-in-event
Add previous server to ServerConnectedEvent
Dieser Commit ist enthalten in:
Commit
09d33de03e
@ -3,6 +3,8 @@ package com.velocitypowered.api.event.player;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
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 org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired once the player has successfully connected to the target server and the
|
* This event is fired once the player has successfully connected to the target server and the
|
||||||
@ -12,10 +14,24 @@ public final class ServerConnectedEvent {
|
|||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer server;
|
private final RegisteredServer server;
|
||||||
|
private final @Nullable RegisteredServer previousServer;
|
||||||
|
|
||||||
public ServerConnectedEvent(Player player, RegisteredServer server) {
|
/**
|
||||||
|
* 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, null if none
|
||||||
|
*/
|
||||||
|
public ServerConnectedEvent(Player player, RegisteredServer server,
|
||||||
|
@Nullable RegisteredServer previousServer) {
|
||||||
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.previousServer = previousServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public ServerConnectedEvent(Player player, RegisteredServer server) {
|
||||||
|
this(player, server, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
@ -26,11 +42,16 @@ public final class ServerConnectedEvent {
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<RegisteredServer> getPreviousServer() {
|
||||||
|
return Optional.ofNullable(previousServer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ServerConnectedEvent{"
|
return "ServerConnectedEvent{"
|
||||||
+ "player=" + player
|
+ "player=" + player
|
||||||
+ ", server=" + server
|
+ ", server=" + server
|
||||||
|
+ ", previousServer=" + previousServer
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// The goods are in hand! We got JoinGame. Let's transition completely to the new state.
|
||||||
smc.setAutoReading(false);
|
smc.setAutoReading(false);
|
||||||
server.getEventManager()
|
server.getEventManager()
|
||||||
.fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer()))
|
.fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer(),
|
||||||
|
existingConnection != null ? existingConnection.getServer() : null))
|
||||||
.whenCompleteAsync((x, error) -> {
|
.whenCompleteAsync((x, error) -> {
|
||||||
// Strap on the ClientPlaySessionHandler if required.
|
// Strap on the ClientPlaySessionHandler if required.
|
||||||
ClientPlaySessionHandler playHandler;
|
ClientPlaySessionHandler playHandler;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren