Class ConnectionManager

java.lang.Object
net.minestom.server.network.ConnectionManager

public final class ConnectionManager extends Object
Manages the connected clients.
  • Constructor Details

    • ConnectionManager

      public ConnectionManager()
  • Method Details

    • getOnlinePlayerCount

      public int getOnlinePlayerCount()
      Gets the number of "online" players, eg for the query response.

      Only includes players in the play state, not players in configuration.

    • getOnlinePlayers

      @NotNull public @NotNull Collection<@NotNull Player> getOnlinePlayers()
      Returns an unmodifiable set containing the players currently in the play state.
    • getConfigPlayers

      @NotNull public @NotNull Collection<@NotNull Player> getConfigPlayers()
      Returns an unmodifiable set containing the players currently in the configuration state.
    • getPlayer

      public Player getPlayer(@NotNull @NotNull PlayerConnection connection)
      Gets the Player linked to a PlayerConnection.

      The player will be returned whether they are in the play or config state, so be sure to check before sending packets to them.

      Parameters:
      connection - the player connection
      Returns:
      the player linked to the connection
    • getOnlinePlayerByUsername

      @Nullable public @Nullable Player getOnlinePlayerByUsername(@NotNull @NotNull String username)
      Gets the first player in the play state which validates String.equalsIgnoreCase(String).

      This can cause issue if two or more players have the same username.

      Parameters:
      username - the player username (case-insensitive)
      Returns:
      the first player who validate the username condition, null if none was found
    • getOnlinePlayerByUuid

      @Nullable public @Nullable Player getOnlinePlayerByUuid(@NotNull @NotNull UUID uuid)
      Gets the first player in the play state which validates UUID.equals(Object).

      This can cause issue if two or more players have the same UUID.

      Parameters:
      uuid - the player UUID
      Returns:
      the first player who validate the UUID condition, null if none was found
    • findOnlinePlayer

      @Nullable public @Nullable Player findOnlinePlayer(@NotNull @NotNull String username)
      Finds the closest player in the play state matching a given username.
      Parameters:
      username - the player username (can be partial)
      Returns:
      the closest match, null if no players are online
    • setUuidProvider

      public void setUuidProvider(@Nullable @Nullable UuidProvider uuidProvider)
      Changes how UUID are attributed to players.

      Shouldn't be override if already defined.

      Be aware that it is possible for an UUID provider to be ignored, for example in the case of a proxy (eg: velocity).

      Parameters:
      uuidProvider - the new player connection uuid provider, setting it to null would apply a random UUID for each player connection
      See Also:
    • getPlayerConnectionUuid

      @NotNull public @NotNull UUID getPlayerConnectionUuid(@NotNull @NotNull PlayerConnection playerConnection, @NotNull @NotNull String username)
      Computes the UUID of the specified connection. Used in ClientLoginStartPacket in order to give the player the right UUID.
      Parameters:
      playerConnection - the player connection
      username - the username given by the connection
      Returns:
      the uuid based on playerConnection return a random UUID if no UUID provider is defined see setUuidProvider(UuidProvider)
    • setPlayerProvider

      public void setPlayerProvider(@Nullable @Nullable PlayerProvider playerProvider)
      Changes the Player provider, to change which object to link to him.
      Parameters:
      playerProvider - the new PlayerProvider, can be set to null to apply the default provider
    • createPlayer

      @Internal @NotNull public @NotNull Player createPlayer(@NotNull @NotNull PlayerConnection connection, @NotNull @NotNull UUID uuid, @NotNull @NotNull String username)
      Creates a player object and begins the transition from the login state to the config state.
    • transitionLoginToConfig

      @Internal @NotNull public @NotNull CompletableFuture<Void> transitionLoginToConfig(@NotNull @NotNull Player player)
    • transitionPlayToConfig

      @Internal public void transitionPlayToConfig(@NotNull @NotNull Player player)
    • doConfiguration

      @Internal public CompletableFuture<Void> doConfiguration(@NotNull @NotNull Player player, boolean isFirstConfig)
      Return value exposed for testing
    • transitionConfigToPlay

      @Internal public void transitionConfigToPlay(@NotNull @NotNull Player player)
    • removePlayer

      @Internal public void removePlayer(@NotNull @NotNull PlayerConnection connection)
      Removes a Player from the players list.

      Used during disconnection, you shouldn't have to do it manually.

      Parameters:
      connection - the player connection
      See Also:
    • shutdown

      public void shutdown()
      Shutdowns the connection manager by kicking all the currently connected players.
    • tick

      public void tick(long tickStart)
    • updateWaitingPlayers

      @Internal public void updateWaitingPlayers()
      Connects waiting players.