Player Data
Register and access custom player data
- Registering a custom player data tag
- Check if Key is registered
- Check if persistent / syncs
- Get Tag from Player
- Set Tag for Player
Registering a custom player data tag
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);
Check if Key is registered
You can use PlayerDataRegistry.isKeyRegistered(key)
to check if your key is registered.
PlayerDataRegistry.keySet().contains(key);
Check if persistent / syncs
You can use PlayerDataRegistry.isKeyPersistent(key)
to check if a key is persistent and PlayerDataRegistry.shouldSyncKey(key)
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)
and to check, whether it should sync to other players, use PlayerDataRegistry.shouldSyncTagToAll(key)
.
Get Tag from Player
Get the Tag value for the specified key.
Requires the tag to be registered!
PlayerDataRegistry.readTag(player, key);
Set Tag for Player
Set the Tag value for the specified key.
Requires the tag to be registered!
PlayerDataRegistry.writeTag(player, key, value);
Continue with Player Profile