Class Player

java.lang.Object
org.ngengine.player.Player
Direct Known Subclasses:
LocalPlayer

public class Player extends Object
  • Field Details

    • SUPPORTED_PLAYER_IMAGE_EXTENSIONS

      public static final List<String> SUPPORTED_PLAYER_IMAGE_EXTENSIONS
    • MAX_PLAYER_IMAGE_SIZE

      public static int MAX_PLAYER_IMAGE_SIZE
    • playerManager

      protected PlayerManagerComponent playerManager
    • pubkey

      protected org.ngengine.nostr4j.keypair.NostrPublicKey pubkey
    • onUpdateCallbacks

      protected List<Supplier<CallbackPolicy>> onUpdateCallbacks
    • gamerTag

      protected GamerTag gamerTag
    • name

      protected String name
    • metadata

      protected org.ngengine.platform.AsyncTask<org.ngengine.nostr4j.nip24.Nip24ExtraMetadata> metadata
    • image

      protected Texture2D image
  • Constructor Details

  • Method Details

    • getPlayerManager

      protected PlayerManagerComponent getPlayerManager()
    • callOnUpdate

      protected void callOnUpdate()
    • resetCached

      protected void resetCached()
      Reset the cached values
    • refresh

      public void refresh()
      Triggers a refresh of the player data.

      The refresh runs asynchronously and can be awaited using ensureReady(), but this is discouraged as it will block the caller thread. Instead, you should use the placeholder values returned by the getters and register an update listener using

      invalid reference
      #addUpdateListener(Runnable)
      to be notified when the data changes and update your logic accordingly.

      The data will be refreshed once after you call this method and will not update automatically afterward. If you need to keep the data up to date, you must call this method periodically.

    • ensureReady

      public void ensureReady()
      Waits for the player to be fully updated and ready.

      This is a blocking operation and should generally be avoided. Instead, use the placeholder values returned by the getters and register an update listener using

      invalid reference
      #addUpdateListener(Runnable)
      to be notified when the data changes and update your logic accordingly.

    • getMetatada

      public org.ngengine.nostr4j.nip24.Nip24ExtraMetadata getMetatada()
      Return the metadata if they are fetched and ready to be used. Otherwise, return null.
      Returns:
      the metadata if they are ready, null otherwise.
    • getUID

      public String getUID()
      Return the unique user id (bech32 of the pubkey). Can be used to uniquely identify the user.
      Returns:
      the unique user id (bech32 of the pubkey).
    • getName

      public String getName()
      Return the best name for the user. This can be used to display the user name in the UI or to other players. It will preferably return the gamertag if set, otherwise it will return the first name-like field from the user metadata event. If metadata are not available yet, this will return a shortned version of the UID. Note: this can change at any time, even with no user action, as more info reach the client.
      Returns:
      the best name for the user.
    • getGamerTag

      public GamerTag getGamerTag()
      Return the gamertag if set, null otherwise. If the metadata are not available yet, this will return null. The gamertag is a special uncommon identifier for the player, it can be used to search for a player, or as display name, but shouldn't be trusted to be an unique identifier, for that use getUID().
      Returns:
      the gamertag if set and available, null otherwise.
    • getImage

      public Texture2D getImage()
      Returns the image of the player.

      This method returns a Texture2D object that can be used to display the player's image. Initially, it will contain a default image, which will be replaced with the actual player image once it is loaded from the network.

      You can use this in a Material and it will be automatically updated. Otherwise, you should register an update listener and implement your own update logic.

      Returns:
      the image of the player.
    • addUpdateListener

      public void addUpdateListener(Supplier<CallbackPolicy> r)
      Add an update listener that will be called when the player data is updated.
      Parameters:
      r -
    • removeUpdateListener

      public void removeUpdateListener(Supplier<CallbackPolicy> r)
      Remove an update listener that was previously added.
      Parameters:
      r -