Class Player

java.lang.Object
de.rexlcloud.core.api.Player
All Implemented Interfaces:
Serializable

public class Player extends Object implements Serializable
A player who is online on the network: on which proxy and server, and since when.

The object is updated by the cloud while the player is online (e.g. getServer() after a server switch). Actions like connect(String) or sendMessage(Component) are carried out by the player's proxy. Players can also have data that plugins store for them in the cloud's database (setData(String, T)); it stays when they leave and is available on every server.

See Also:
  • Constructor Details

  • Method Details

    • update

      protected void update(@NonNull @NonNull Player player, @NonNull @NonNull Server server)
      Internal: applies a newer state of the player.
    • getData

      public <T extends Serializable> Optional<T> getData(String key)
      Data a plugin stored for this player. Only JDK value types and classes of the calling plugin are read; data of other types is treated as missing.
    • setData

      public <T extends Serializable> boolean setData(@NonNull @NonNull String key, @NonNull T value)
      Stores data for the player in the cloud's database, replacing a value with the same key. The value is serialized with Java serialization; only JDK value types (strings, numbers, collections, time types) and classes of the plugin itself can be read back with getData(String).
      Type Parameters:
      T - type of the value
      Parameters:
      key - name of the value, e.g. "coins"
      value - the value
      Returns:
      false if the value could not be serialized
    • hasData

      public boolean hasData(String key)
      Parameters:
      key - name of a value
      Returns:
      whether the player has data under this key
    • removeData

      public void removeData(String key)
      Removes the player's data under this key from the database.
      Parameters:
      key - name of the value
    • updateData

      protected void updateData(String key, byte[] data)
      Internal: applies data changed on another server.
    • kick

      public CompletableFuture<Boolean> kick(@Nullable @Nullable String message)
      Disconnects the player from the network.
      Parameters:
      message - reason shown to the player (MiniMessage or & colour codes), null for none
      Returns:
      completes once the proxy received the request
    • sendMessage

      public CompletableFuture<Boolean> sendMessage(@Nullable @Nullable String message)
      Sends a plain text message to the player.
      Parameters:
      message - the text
      Returns:
      completes once the proxy received the request
    • sendMessage

      public CompletableFuture<Boolean> sendMessage(@Nullable @Nullable net.kyori.adventure.text.Component message)
      Sends a chat message to the player, e.g. one built with Adventure or CloudText.parse(String).
      Parameters:
      message - the message
      Returns:
      completes once the proxy received the request
    • connect

      public CompletableFuture<Boolean> connect(@NonNull @NonNull Server server)
      Sends the player to another server.
      Parameters:
      server - the target server
      Returns:
      completes once the proxy received the request
    • connect

      public CompletableFuture<Boolean> connect(@NonNull @NonNull String serverName)
      Sends the player to another server.
      Parameters:
      serverName - name of the target server
      Returns:
      completes once the proxy received the request
    • connectToFallbackServer

      public CompletableFuture<Boolean> connectToFallbackServer()
      Sends the player to a fallback server (a server of a group marked as fallback, e.g. a lobby).
      Returns:
      completes once the proxy received the request
    • connectAndTeleport

      public CompletableFuture<Boolean> connectAndTeleport(@NonNull @NonNull Server server, @NonNull @NonNull ServerLocation serverLocation)
      Sends the player to another server and teleports them there once they arrived.
      Parameters:
      server - the target server
      serverLocation - where on it
      Returns:
      completes once the proxy received the request
    • connectAndTeleport

      public CompletableFuture<Boolean> connectAndTeleport(@NonNull @NonNull String serverName, @NonNull @NonNull ServerLocation serverLocation)
      Sends the player to another server and teleports them there once they arrived.
      Parameters:
      serverName - name of the target server
      serverLocation - where on it
      Returns:
      completes once the proxy received the request
    • teleport

      public CompletableFuture<Boolean> teleport(ServerLocation serverLocation)
      Teleports the player on the server they are on.
      Parameters:
      serverLocation - the target; its world name selects the world
      Returns:
      completes once the server received the request
    • getLocation

      public CompletableFuture<ServerLocation> getLocation()
      Returns:
      where the player is, asked from their server
    • getName

      @NonNull public @NonNull String getName()
      The player's name.
    • getUuid

      @NotNull public @NotNull UUID getUuid()
      The player's UUID.
    • getServer

      @NonNull public @NonNull Server getServer()
      The server the player is on.
    • getProxyServer

      @NonNull public @NonNull Server getProxyServer()
      The proxy the player is connected through.
    • getLogin

      public long getLogin()
      When the player joined the network, in milliseconds since the epoch.
    • getData

      public ArrayList<PlayerDatabaseData> getData()
      The stored data entries of the player; read them with getData(String).