-
Notifications
You must be signed in to change notification settings - Fork 0
Accessing Data
Evyatar edited this page Jul 30, 2023
·
11 revisions
The API was designed mainly to perform great while providing an easy and accessible approach to persistent data containers found in entities, blocks, etc.
Using the class: DataRegistry, you can easily access an item's, a player's or a block's persistent data.
The method used to access persistent data is:
@Override
public void onEnable() {
PersistentDataAPI api = new PersistentDataAPI(this);
DataRegistry data = api.getDataRegistry(player/item/block object);
}After accessing an object's Dataregistry, we can use some methods:
| Method | Parameters | Exceptions thrown | Description |
|---|---|---|---|
| registerData() | AbstractPersistentData / dataName, dataValue | DataException if data already exists | Registers a new data That doesn't exist |
| unregisterData() | AbstractPersistentData / dataName | DataException if data doesn't exist | Deletes a registered data |
| setData() | AbstractPersistentData / dataName, dataValue | none | Changes existing data's value. If data doesn't exist, it will create it |
| getData() | AbstractPersistentData / dataName | DataException if data doesn't exist | Returns the value of the requested data |
| getAll() | none | none | Returns all keys and values of the given object's data container, in a HashMap |
| getKeys() | none | none | Returns all keys of the given object's container in a Set |
| getDataAsBytes() | AbstractPersistentData / dataName | DataException if data doesn't exist | Returns the data serialized to bytes (as an array of bytes) |
| dataExist() | AbstractPersistentData / dataName | none | Returns true if the requested data exists, false otherwise |