-
-
Notifications
You must be signed in to change notification settings - Fork 1
Player Data
First, you need to register a tag in the player data that should be watched.
PlayerDataRegistry.registerKey(key, persistent, sync);
key
is the Tag Key in the NBT Data of the Player.
persistent
means the key will be restored when the player respawns and keepInventory is false
.
When sync
is true
, the value will be synced to all clients.
Or, if you want to specificy, whether it should just sync to it's owner instead of all players, you can use the following code:
PlayerDataRegistry.registerKey(key, persistent, syncToSelf, syncsToAll);
You can use PlayerDataRegistry.isKeyRegistered(key)
{:.language-java .highlight} to check if your key is registered.
PlayerDataRegistry.keySet().contains(key);
You can use PlayerDataRegistry.isKeyPersistent(key)
{:.language-java .highlight} to check if a key is persistent and PlayerDataRegistry.shouldSyncKey(key)
{:.language-java .highlight} to check if a key syncs to all clients.
To check if your key syncs to the owner of the nbt tag, use PlayerDataRegistry.shouldSyncTagToSelf(key)
{:.language-java .highlight} and to check, whether it should sync to other players, use PlayerDataRegistry.shouldSyncTagToAll(key)
{:.language-java .highlight}.
Get the Tag value for the specified key.
Requires the tag to be registered! {:.note}
PlayerDataRegistry.readTag(player, key);
Set the Tag value for the specified key.
Requires the tag to be registered! {:.note}
PlayerDataRegistry.writeTag(player, key, value);