Package net.minestom.server.network
Class ConnectionManager
java.lang.Object
net.minestom.server.network.ConnectionManager
Manages the connected clients.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription@NotNull Player
createPlayer
(@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.void
doConfiguration
(@NotNull Player player, boolean isFirstConfig) @Nullable Player
findOnlinePlayer
(@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 Player
getOnlinePlayerByUsername
(@NotNull String username) Gets the first player in the play state which validatesString.equalsIgnoreCase(String)
.@Nullable Player
getOnlinePlayerByUuid
(@NotNull UUID uuid) Gets the first player in the play state which validatesUUID.equals(Object)
.int
Gets 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 thePlayer
linked to aPlayerConnection
.@NotNull UUID
getPlayerConnectionUuid
(@NotNull PlayerConnection playerConnection, @NotNull String username) Computes the UUID of the specified connection.void
removePlayer
(@NotNull PlayerConnection connection) Removes aPlayer
from the players list.void
setPlayerProvider
(@Nullable PlayerProvider playerProvider) Changes thePlayer
provider, to change which object to link to him.void
setUuidProvider
(@Nullable UuidProvider uuidProvider) Changes howUUID
are attributed to players.void
shutdown()
Shutdowns the connection manager by kicking all the currently connected players.void
tick
(long tickStart) void
transitionConfigToPlay
(@NotNull Player player) @NotNull CompletableFuture
<Void> transitionLoginToConfig
(@NotNull Player player) void
transitionPlayToConfig
(@NotNull Player player) void
Connects 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 thePlayer
linked 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 howUUID
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 inClientLoginStartPacket
in order to give the player the rightUUID
.- Parameters:
playerConnection
- the player connectionusername
- the username given by the connection- Returns:
- the uuid based on
playerConnection
return a random UUID if no UUID provider is defined seesetUuidProvider(UuidProvider)
-
setPlayerProvider
Changes thePlayer
provider, 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 aPlayer
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.
-