Class OfflinePlayer

java.lang.Object
fr.fidorial.entity.OfflinePlayer

public final class OfflinePlayer extends Object
  • Method Details

    • of

      @Internal @Contract(value="_, _, _, _, _ -> new", pure=true) public static OfflinePlayer of(OfflinePlayers registry, UUID uuid, @Nullable String name, long firstSeen, long lastSeen)
      Creates a handle bound to the given registry.
      Parameters:
      registry - the registry serving the state-dependent operations
      uuid - the player identity
      name - the last known name, or null if none was ever observed
      firstSeen - the epoch milliseconds of the first observation, or 0 if unknown
      lastSeen - the epoch milliseconds of the most recent observation, or 0 if unknown
      Returns:
      a new handle
      Since:
      0.1.0
    • uuid

      @Contract(pure=true) public UUID uuid()
      Gets the unique identifier of this player.
      Returns:
      the player identity
      Since:
      0.1.0
    • name

      @Contract(pure=true) public Optional<String> name()
      Gets the most recent name observed for uuid().
      Returns:
      the last known name, or empty if none is known
      Since:
      0.1.0
    • label

      @Contract(pure=true) public String label()
      Gets a label suitable for display, falling back to the identity when no name is known.
      Returns:
      the last known name, or the string form of uuid()
      Since:
      0.1.0
    • hasPlayedBefore

      @Contract(pure=true) public boolean hasPlayedBefore()
      Checks whether the server holds any record of this identity.
      Returns:
      true if this identity has been observed at least once
      Since:
      0.1.0
    • firstSeen

      @Contract(pure=true) public Optional<Instant> firstSeen()
      Gets the time at which this identity was first observed.
      Returns:
      the first observation, or empty if this identity has never been observed
      Since:
      0.1.0
    • lastSeen

      @Contract(pure=true) public Optional<Instant> lastSeen()
      Gets the time at which this identity was most recently observed.
      Returns:
      the most recent observation, or empty if this identity has never been observed
      Since:
      0.1.0
    • online

      public Optional<? extends Player> online()
      Gets the connected player behind this identity.
      Returns:
      the connected player, or empty if this identity is not connected
      Since:
      0.1.0
    • isOnline

      public boolean isOnline()
      Checks whether this identity is currently connected.
      Returns:
      true if a player with this identity is connected
      Since:
      0.1.0
    • ifOnline

      public void ifOnline(Consumer<? super Player> action)
      Performs the given action on the connected player behind this identity, if there is one.
      Parameters:
      action - the action to perform
      Since:
      0.1.0
    • isOperator

      public boolean isOperator()
      Checks whether this identity holds operator status.
      Returns:
      true if this identity is an operator
      Since:
      0.1.0
    • setOperator

      public void setOperator(boolean operator)
      Sets the operator status of this identity.
      Parameters:
      operator - the new operator status
      Since:
      0.1.0
    • snapshot

      Reads the saved state of this identity.
      Returns:
      a future completing with the saved state, or with an empty result if none exists
      Since:
      0.1.0
    • refresh

      public CompletableFuture<OfflinePlayer> refresh()
      Produces an updated handle for this identity.
      Returns:
      a future completing with an updated handle for the same identity
      Since:
      0.1.0
    • equals

      public boolean equals(@Nullable Object o)
      Compares handles by identity. Names and observation times are not considered.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare against
      Returns:
      true if the argument is a handle for the same identity
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object