Class PlayerChooseInitialServerEvent

java.lang.Object
com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent

@AwaitingEvent public class PlayerChooseInitialServerEvent extends Object
Fired when a player has finished the login process, and we need to choose the first server to connect to. Velocity will wait on this event to finish firing before initiating the connection, but you should try to limit the work done in this event. Failures will be handled by KickedFromServerEvent as normal.
  • Constructor Details

    • PlayerChooseInitialServerEvent

      public PlayerChooseInitialServerEvent(Player player, @Nullable RegisteredServer initialServer)
      Constructs a PlayerChooseInitialServerEvent.
      Parameters:
      player - the player that was connected
      initialServer - the initial server selected, may be null
  • Method Details

    • getPlayer

      public Player getPlayer()
      Gets the player who is choosing the initial server.
      Returns:
      the connected player
    • getInitialServer

      public Optional<RegisteredServer> getInitialServer()
      Gets the initial server the player will connect to.
      Returns:
      an Optional containing the selected server, or empty if none was set
    • setInitialServer

      public void setInitialServer(@Nullable RegisteredServer server)
      Sets the new initial server.
      Parameters:
      server - the initial server the player should connect to
    • getReason

      public Optional<Component> getReason()
      Returns the reason the player will be disconnected if no initial server is selected.

      The proxy seeds this with a default human-readable message before firing the event, so this will usually be present. Plugins may override or clear it.

      Returns:
      the disconnect reason, or Optional.empty() if a plugin explicitly cleared it (in which case the proxy will still fall back to its default message)
    • setReason

      public void setReason(@Nullable Component reason)
      Sets a custom disconnect reason for the player.

      Passing null clears the custom reason. The proxy will then fall back to its default disconnect message if no initial server is ultimately selected.

      Parameters:
      reason - the disconnect reason to show to the player
    • toString

      public String toString()
      Returns a string representation of this PlayerChooseInitialServerEvent.

      The output includes the player, the selected initial server (if any), and the disconnect reason (if set).

      Overrides:
      toString in class Object
      Returns:
      a human-readable string describing this event