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
    • 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 GameProfile gameProfile)
    • transitionLoginToConfig

      public GameProfile transitionLoginToConfig(@NotNull @NotNull PlayerConnection connection, @NotNull @NotNull GameProfile gameProfile)
    • transitionPlayToConfig

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

      @Internal public 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.