Class PlayerConnection

java.lang.Object
net.minestom.server.network.player.PlayerConnection
Direct Known Subclasses:
PlayerSocketConnection

public abstract class PlayerConnection extends Object
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 Details

    • PlayerConnection

      public PlayerConnection()
  • Method Details

    • getIdentifier

      @NotNull public @NotNull String getIdentifier()
      Returns a printable identifier for this connection, will be the player username or the connection remote address.
      Returns:
      this connection identifier
    • sendPacket

      public abstract void sendPacket(@NotNull @NotNull SendablePacket packet)
      Serializes the packet and send it to the client.
      Parameters:
      packet - the packet to send
    • sendPackets

      public void sendPackets(@NotNull @NotNull Collection<SendablePacket> packets)
    • sendPackets

      public void sendPackets(@NotNull @NotNull SendablePacket... packets)
    • getRemoteAddress

      @NotNull public abstract @NotNull SocketAddress 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

      @Nullable public @Nullable String 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
    • disconnect

      public void disconnect()
      Forcing the player to disconnect.
    • getPlayer

      @Nullable public @Nullable Player getPlayer()
      Gets the player linked to this connection.
      Returns:
      the player, can be null if not initialized yet
    • setPlayer

      public void setPlayer(Player player)
      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

      public void setConnectionState(@NotNull @NotNull ConnectionState connectionState)
    • getConnectionState

      @NotNull public @NotNull ConnectionState getConnectionState()
      Gets the client connection state.
      Returns:
      the client connection state
    • playerPublicKey

      public PlayerPublicKey playerPublicKey()
    • setPlayerPublicKey

      public void setPlayerPublicKey(PlayerPublicKey playerPublicKey)
    • storeCookie

      public void storeCookie(@NotNull @NotNull String key, byte @NotNull [] data)
    • fetchCookie

      public CompletableFuture<byte @Nullable []> fetchCookie(@NotNull @NotNull String key)
    • receiveCookieResponse

      @Internal public void receiveCookieResponse(@NotNull @NotNull String key, byte @Nullable [] data)
    • loginPluginMessageProcessor

      @Internal @NotNull public @NotNull LoginPluginMessageProcessor 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

      public String toString()
      Overrides:
      toString in class Object