Package net.minestom.server.network
Class ConnectionManager
java.lang.Object
net.minestom.server.network.ConnectionManager
Manages the connected clients.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull PlayercreatePlayer(@NotNull PlayerConnection connection, @NotNull UUID uuid, @NotNull String username) Creates a player object and begins the transition from the login state to the config state.voiddoConfiguration(@NotNull Player player, boolean isFirstConfig) @Nullable PlayerfindOnlinePlayer(@NotNull String username) Finds the closest player in the play state matching a given username.@NotNull Collection<@NotNull Player> Returns an unmodifiable set containing the players currently in the configuration state.@Nullable PlayergetOnlinePlayerByUsername(@NotNull String username) Gets the first player in the play state which validatesString.equalsIgnoreCase(String).@Nullable PlayergetOnlinePlayerByUuid(@NotNull UUID uuid) Gets the first player in the play state which validatesUUID.equals(Object).intGets the number of "online" players, eg for the query response.@NotNull Collection<@NotNull Player> Returns an unmodifiable set containing the players currently in the play state.getPlayer(@NotNull PlayerConnection connection) Gets thePlayerlinked to aPlayerConnection.@NotNull UUIDgetPlayerConnectionUuid(@NotNull PlayerConnection playerConnection, @NotNull String username) Computes the UUID of the specified connection.voidremovePlayer(@NotNull PlayerConnection connection) Removes aPlayerfrom the players list.voidsetPlayerProvider(@Nullable PlayerProvider playerProvider) Changes thePlayerprovider, to change which object to link to him.voidsetUuidProvider(@Nullable UuidProvider uuidProvider) Changes howUUIDare attributed to players.voidshutdown()Shutdowns the connection manager by kicking all the currently connected players.voidtick(long tickStart) voidtransitionConfigToPlay(@NotNull Player player) @NotNull CompletableFuture<Void> transitionLoginToConfig(@NotNull Player player) voidtransitionPlayToConfig(@NotNull Player player) voidConnects waiting players.
-
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
Returns an unmodifiable set containing the players currently in the play state. -
getConfigPlayers
Returns an unmodifiable set containing the players currently in the configuration state. -
getPlayer
Gets thePlayerlinked to aPlayerConnection.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
Gets the first player in the play state which validatesString.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
Gets the first player in the play state which validatesUUID.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
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
Changes howUUIDare 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 inClientLoginStartPacketin order to give the player the rightUUID.- Parameters:
playerConnection- the player connectionusername- the username given by the connection- Returns:
- the uuid based on
playerConnectionreturn a random UUID if no UUID provider is defined seesetUuidProvider(UuidProvider)
-
setPlayerProvider
Changes thePlayerprovider, to change which object to link to him.- Parameters:
playerProvider- the newPlayerProvider, 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
-
doConfiguration
-
transitionConfigToPlay
-
removePlayer
Removes aPlayerfrom 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.
-