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 GameProfile gameProfile) void
doConfiguration
(@NotNull Player player, boolean isFirstConfig) Return value exposed for testing@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
.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
shutdown()
Shutdowns the connection manager by kicking all the currently connected players.void
tick
(long tickStart) void
transitionConfigToPlay
(@NotNull Player player) transitionLoginToConfig
(@NotNull PlayerConnection connection, @NotNull GameProfile gameProfile) 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
-
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 GameProfile gameProfile) -
transitionLoginToConfig
public GameProfile transitionLoginToConfig(@NotNull @NotNull PlayerConnection connection, @NotNull @NotNull GameProfile gameProfile) -
transitionPlayToConfig
-
doConfiguration
Return value exposed for testing -
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.
-