fix missing server info in some events when kicked from current server (#703)
This commit is contained in:
committed by
GitHub
parent
aa38d3e561
commit
3ae93875b8
@@ -13,6 +13,7 @@ import com.velocitypowered.api.event.annotation.AwaitingEvent;
|
||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder.Status;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -27,6 +28,7 @@ public final class ServerPreConnectEvent implements
|
||||
|
||||
private final Player player;
|
||||
private final RegisteredServer originalServer;
|
||||
private final RegisteredServer previousServer;
|
||||
private ServerResult result;
|
||||
|
||||
/**
|
||||
@@ -35,8 +37,21 @@ public final class ServerPreConnectEvent implements
|
||||
* @param originalServer the server the player was trying to connect to
|
||||
*/
|
||||
public ServerPreConnectEvent(Player player, RegisteredServer originalServer) {
|
||||
this(player, originalServer,
|
||||
player.getCurrentServer().map(ServerConnection::getServer).orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ServerPreConnectEvent.
|
||||
* @param player the player who is connecting to a server
|
||||
* @param originalServer the server the player was trying to connect to
|
||||
* @param previousServer the server the player ís connected to
|
||||
*/
|
||||
public ServerPreConnectEvent(Player player, RegisteredServer originalServer,
|
||||
@Nullable RegisteredServer previousServer) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer");
|
||||
this.previousServer = previousServer;
|
||||
this.result = ServerResult.allowed(originalServer);
|
||||
}
|
||||
|
||||
@@ -61,13 +76,24 @@ public final class ServerPreConnectEvent implements
|
||||
/**
|
||||
* Returns the server that the player originally tried to connect to. To get the server the
|
||||
* player will connect to, see the {@link ServerResult} of this event. To get the server the
|
||||
* player is currently on when this event is fired, use {@link Player#getCurrentServer()}.
|
||||
* player is currently on when this event is fired, use {@link #getPreviousServer()}.
|
||||
* @return the server that the player originally tried to connect to
|
||||
*/
|
||||
public RegisteredServer getOriginalServer() {
|
||||
return originalServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server that the player is currently connected to. Prefer this method over using
|
||||
* {@link Player#getCurrentServer()} as the current server might get reset after server kicks to
|
||||
* prevent connection issues. This is {@code null} if they were not connected to another server
|
||||
* beforehand (for instance, if the player has just joined the proxy).
|
||||
* @return the server the player is currently connected to.
|
||||
*/
|
||||
public @Nullable RegisteredServer getPreviousServer() {
|
||||
return previousServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServerPreConnectEvent{"
|
||||
|
@@ -11,6 +11,7 @@ import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents a connection to a backend server from the proxy for a client.
|
||||
@@ -24,6 +25,14 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi
|
||||
*/
|
||||
RegisteredServer getServer();
|
||||
|
||||
/**
|
||||
* Returns the server that the player associated with this connection was connected to before
|
||||
* switching to this connection.
|
||||
*
|
||||
* @return the server the player was connected to.
|
||||
*/
|
||||
Optional<RegisteredServer> getPreviousServer();
|
||||
|
||||
/**
|
||||
* Returns the server info for this connection.
|
||||
*
|
||||
|
Reference in New Issue
Block a user