Handle player data
This page is about how to handle player data while enabling or disabling a staff mod.
Introduction
When setting a player is staff mod, we'll modify his inventory and eventually some other data. However, we would like to keep
some data (game mode, potion effects, health, food level) to restore them later. So, the library provides a class called PlayerDataHandler
which will allow us to do that.
How to create it ?
To create a new PlayerDataHandler
instance, you will need a list of object of classes that implement the DataHandler<Player>
interface. Each of which handle a specific data type.
Predefined data classes
Class
Description
InventoryDataHandler
Handle player's inventory including his armors.
PotionDataHandler
Handle active player's potion effects.
HealthDataHandler
Handle player's health.
FoodDataHandler
Handle player's saturation and food level.
GameModeDataHandler
Handle player's game mode.
Create your data handler
Create your own data class
To create a your own data class, you only have to implements the DataHandler<T>
interface and to redefine the required methods. Let's see an example in which we'll create a FlyDataHandler
class to handle player's fly state.
The generic type is used to specify on which object that represents a player are applied the methods.
Last updated
Was this helpful?