Class PlayerDataKey<T>
java.lang.Object
fr.robie.machineengine.api.player.PlayerDataKey<T>
- All Implemented Interfaces:
net.kyori.adventure.key.Keyed
A value MachineEngine keeps for each player (D37), declared by an addon in its own namespace and
registered with
RegistrationContext#playerData(). Read and written through
MachinePlayer.get(PlayerDataKey)/MachinePlayer.set(PlayerDataKey, T). Values must be immutable.
public static final PlayerDataKey<Double> DOSE = PlayerDataKey.persistent(Key.key("mymod", "dose"),
VersionedCodec.builder(Key.key("mymod", "dose"), Codecs.DOUBLE).build(), 0.0).resetOnDeath();
public static final PlayerDataKey<Long> LAST_TELEPORT = PlayerDataKey.session(Key.key("mymod", "last_teleport"), 0L);
Keys are immutable: resetOnDeath, migratePdc(String, PersistentDataType) and display return a new key.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn entry of the player's PDC an older version wrote, seemigratePdc(String, PersistentDataType). -
Method Summary
Modifier and TypeMethodDescription@Nullable VersionedCodec<T> codec()How the value is saved;nullfor a session key.@NotNull PlayerDataKey<T> How the value is shown in placeholders (%zmenu_machineengine_player_<namespace>_<id>%) and admin commands;String.valueOfby default.@NotNull Stringvalueasdisplayshows it.booleanboolean@NotNull net.kyori.adventure.key.Keykey()@NotNull PlayerDataKey<T> migratePdc(@NotNull String oldKey, @NotNull org.bukkit.persistence.PersistentDataType<?, T> type) Where an older version kept the value: anamespace:keyentry of the player'sPersistentDataContainer.@Nullable PlayerDataKey.PdcMigration<T> static <T> @NotNull PlayerDataKey<T> persistent(@NotNull net.kyori.adventure.key.Key key, @NotNull VersionedCodec<T> codec, T defaultValue) A value saved with the player's data and loaded again when they join.@NotNull PlayerDataKey<T> The value goes back to its default when the player dies.static <T> @NotNull PlayerDataKey<T> session(@NotNull net.kyori.adventure.key.Key key, T defaultValue) A value kept while the player is online and forgotten when they leave; never saved.toString()
-
Method Details
-
persistent
@NotNull public static <T> @NotNull PlayerDataKey<T> persistent(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull VersionedCodec<T> codec, @NotNull T defaultValue) A value saved with the player's data and loaded again when they join. -
session
@NotNull public static <T> @NotNull PlayerDataKey<T> session(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull T defaultValue) A value kept while the player is online and forgotten when they leave; never saved. -
resetOnDeath
The value goes back to its default when the player dies. -
migratePdc
@NotNull public @NotNull PlayerDataKey<T> migratePdc(@NotNull @NotNull String oldKey, @NotNull @NotNull org.bukkit.persistence.PersistentDataType<?, T> type) Where an older version kept the value: anamespace:keyentry of the player'sPersistentDataContainer. When the player joins, a value found there replaces this key's, and the old entry is removed. Only forpersistent(Key, VersionedCodec, T)keys. -
display
@NotNull public @NotNull PlayerDataKey<T> display(@NotNull @NotNull Function<? super T, String> display) How the value is shown in placeholders (%zmenu_machineengine_player_<namespace>_<id>%) and admin commands;String.valueOfby default. -
key
@NotNull public @NotNull net.kyori.adventure.key.Key key()- Specified by:
keyin interfacenet.kyori.adventure.key.Keyed
-
codec
How the value is saved;nullfor a session key. -
isPersistent
public boolean isPersistent() -
defaultValue
-
isResetOnDeath
public boolean isResetOnDeath() -
format
-
pdcMigration
-
toString
-