Class PlayerConnection
java.lang.Object
net.minestom.server.network.player.PlayerConnection
- Direct Known Subclasses:
PlayerSocketConnection
A PlayerConnection is an object needed for all created
Player.
It can be extended to create a new kind of player (NPC for instance).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidForcing the player to disconnect.CompletableFuture<byte @Nullable []> fetchCookie(@NotNull String key) @NotNull ConnectionStateGets the client connection state.@NotNull StringReturns a printable identifier for this connection, will be the player username or the connection remote address.@Nullable PlayerGets the player linked to this connection.intGets protocol version of client.abstract @NotNull SocketAddressGets the remote address of the client.@Nullable StringGets the server address that the client used to connect.intGets the server port that the client used to connect.booleanisOnline()Gets if the client is still connected to the server.voidKicks the player with a reason.@NotNull LoginPluginMessageProcessorGets the login plugin message processor, only available during the login state.voidreceiveCookieResponse(@NotNull String key, byte @Nullable [] data) voidreceiveKnownPacksResponse(@NotNull List<SelectKnownPacksPacket.Entry> clientPacks) @NotNull CompletableFuture<List<SelectKnownPacksPacket.Entry>> requestKnownPacks(@NotNull List<SelectKnownPacksPacket.Entry> serverPacks) abstract voidsendPacket(@NotNull SendablePacket packet) Serializes the packet and send it to the client.voidsendPackets(@NotNull Collection<SendablePacket> packets) voidsendPackets(@NotNull SendablePacket... packets) voidsetConnectionState(@NotNull ConnectionState connectionState) voidChanges the player linked to this connection.voidsetPlayerPublicKey(PlayerPublicKey playerPublicKey) voidstoreCookie(@NotNull String key, byte @NotNull [] data) toString()
-
Constructor Details
-
PlayerConnection
public PlayerConnection()
-
-
Method Details
-
getIdentifier
Returns a printable identifier for this connection, will be the player username or the connection remote address.- Returns:
- this connection identifier
-
sendPacket
Serializes the packet and send it to the client.- Parameters:
packet- the packet to send
-
sendPackets
-
sendPackets
-
getRemoteAddress
Gets the remote address of the client.- Returns:
- the remote address
-
getProtocolVersion
public int getProtocolVersion()Gets protocol version of client.- Returns:
- the protocol version
-
getServerAddress
Gets the server address that the client used to connect.WARNING: it is given by the client, it is possible for it to be wrong.
- Returns:
- the server address used
-
getServerPort
public int getServerPort()Gets the server port that the client used to connect.WARNING: it is given by the client, it is possible for it to be wrong.
- Returns:
- the server port used
-
kick
Kicks the player with a reason.- Parameters:
component- the reason
-
disconnect
public void disconnect()Forcing the player to disconnect. -
getPlayer
Gets the player linked to this connection.- Returns:
- the player, can be null if not initialized yet
-
setPlayer
Changes the player linked to this connection.WARNING: unsafe.
- Parameters:
player- the player
-
isOnline
public boolean isOnline()Gets if the client is still connected to the server.- Returns:
- true if the player is online, false otherwise
-
setConnectionState
-
getConnectionState
Gets the client connection state.- Returns:
- the client connection state
-
playerPublicKey
-
setPlayerPublicKey
-
storeCookie
-
fetchCookie
-
receiveCookieResponse
-
loginPluginMessageProcessor
Gets the login plugin message processor, only available during the login state. -
requestKnownPacks
@Internal @NotNull public @NotNull CompletableFuture<List<SelectKnownPacksPacket.Entry>> requestKnownPacks(@NotNull @NotNull List<SelectKnownPacksPacket.Entry> serverPacks) -
receiveKnownPacksResponse
@Internal public void receiveKnownPacksResponse(@NotNull @NotNull List<SelectKnownPacksPacket.Entry> clientPacks) -
toString
-