Class Player
- Direct Known Subclasses:
LocalPlayer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GamerTag
protected Texture2D
static int
protected org.ngengine.platform.AsyncTask
<org.ngengine.nostr4j.nip24.Nip24ExtraMetadata> protected String
protected List
<Supplier<CallbackPolicy>> protected PlayerManagerComponent
protected org.ngengine.nostr4j.keypair.NostrPublicKey
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Player
(PlayerManagerComponent mng, org.ngengine.nostr4j.keypair.NostrPublicKey pub) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an update listener that will be called when the player data is updated.protected void
void
Waits for the player to be fully updated and ready.Return the gamertag if set, null otherwise.getImage()
Returns the image of the player.org.ngengine.nostr4j.nip24.Nip24ExtraMetadata
Return the metadata if they are fetched and ready to be used.getName()
Return the best name for the user.protected PlayerManagerComponent
getUID()
Return the unique user id (bech32 of the pubkey).void
refresh()
Triggers a refresh of the player data.void
Remove an update listener that was previously added.protected void
Reset the cached values
-
Field Details
-
SUPPORTED_PLAYER_IMAGE_EXTENSIONS
-
MAX_PLAYER_IMAGE_SIZE
public static int MAX_PLAYER_IMAGE_SIZE -
playerManager
-
pubkey
protected org.ngengine.nostr4j.keypair.NostrPublicKey pubkey -
onUpdateCallbacks
-
gamerTag
-
name
-
metadata
protected org.ngengine.platform.AsyncTask<org.ngengine.nostr4j.nip24.Nip24ExtraMetadata> metadata -
image
-
-
Constructor Details
-
Player
-
-
Method Details
-
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 usinginvalid reference
#addUpdateListener(Runnable)
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)
-
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
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
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
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 usegetUID()
.- Returns:
- the gamertag if set and available, null otherwise.
-
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
Add an update listener that will be called when the player data is updated.- Parameters:
r
-
-
removeUpdateListener
Remove an update listener that was previously added.- Parameters:
r
-
-