Class PlayerSetting<T>

java.lang.Object
fr.robie.machineengine.api.player.PlayerSetting<T>
All Implemented Interfaces:
net.kyori.adventure.key.Keyed

public final class PlayerSetting<T> extends Object implements net.kyori.adventure.key.Keyed
A per-player value players change themselves (D37), with /machinesettings or the zMenu settings menu. Registered with RegistrationContext#playerSettings(); read with MachinePlayer.get(PlayerSetting), which applies the server owner's default and lock (players.setting-defaults, players.locked-settings in MachineEngine's config.yml).

The value is saved as text, so a setting's default may change between versions without a migration. Players see the name and description translated on their client (D23): the lang keys setting.<namespace>.<id> and setting.<namespace>.<id>.description of the addon's CraftEngine pack.

public static final PlayerSetting<Boolean> HUD = PlayerSetting.bool(Key.key("mymod", "hud"), true);
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull PlayerSetting<Boolean>
    bool(@NotNull net.kyori.adventure.key.Key key, boolean defaultValue)
    On or off; a click in the menu toggles it.
    static <E extends Enum<E>>
    @NotNull PlayerSetting<E>
    choice(@NotNull net.kyori.adventure.key.Key key, E defaultValue)
    One of the constants of an enum, written in lower case with dashes; a click cycles through them.
    @NotNull PlayerDataKey<T>
    Where the value is kept: a persistent key of the same id, registered with the setting.
    static @NotNull PlayerSetting<Double>
    decimal(@NotNull net.kyori.adventure.key.Key key, double defaultValue, double min, double max, double step)
    A number from min to max; a click adds or removes step.
     
    @NotNull String
    Lang key of the setting's one-line description.
    @NotNull String
    What a valid value looks like: "true or false".
    @NotNull String
    format(T value)
    The value as players type it.
    @NotNull net.kyori.adventure.key.Key
    key()
     
    @NotNull String
    Lang key of the setting's name.
    parse(@NotNull String text)
    The value text stands for ("on", "12", "fast-mode"), or null if it is not valid.
    step(T current, boolean forward)
    The value after one click in the menu: toggled, the next (or previous) choice, or one step more (or less).
    @NotNull List<String>
    Values offered when the player types the command.
     
    static @NotNull PlayerSetting<Long>
    whole(@NotNull net.kyori.adventure.key.Key key, long defaultValue, long min, long max, long step)
    A whole number from min to max; a click adds or removes step.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • bool

      @NotNull public static @NotNull PlayerSetting<Boolean> bool(@NotNull @NotNull net.kyori.adventure.key.Key key, boolean defaultValue)
      On or off; a click in the menu toggles it.
    • choice

      @NotNull public static <E extends Enum<E>> @NotNull PlayerSetting<E> choice(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull E defaultValue)
      One of the constants of an enum, written in lower case with dashes; a click cycles through them.
    • whole

      @NotNull public static @NotNull PlayerSetting<Long> whole(@NotNull @NotNull net.kyori.adventure.key.Key key, long defaultValue, long min, long max, long step)
      A whole number from min to max; a click adds or removes step.
    • decimal

      @NotNull public static @NotNull PlayerSetting<Double> decimal(@NotNull @NotNull net.kyori.adventure.key.Key key, double defaultValue, double min, double max, double step)
      A number from min to max; a click adds or removes step.
    • key

      @NotNull public @NotNull net.kyori.adventure.key.Key key()
      Specified by:
      key in interface net.kyori.adventure.key.Keyed
    • defaultValue

      @NotNull public T defaultValue()
    • data

      @NotNull public @NotNull PlayerDataKey<T> data()
      Where the value is kept: a persistent key of the same id, registered with the setting.
    • parse

      @Nullable public T parse(@NotNull @NotNull String text)
      The value text stands for ("on", "12", "fast-mode"), or null if it is not valid.
    • format

      @NotNull public @NotNull String format(@NotNull T value)
      The value as players type it.
    • step

      @NotNull public T step(@NotNull T current, boolean forward)
      The value after one click in the menu: toggled, the next (or previous) choice, or one step more (or less).
    • suggestions

      @NotNull public @NotNull List<String> suggestions()
      Values offered when the player types the command.
    • expected

      @NotNull public @NotNull String expected()
      What a valid value looks like: "true or false".
    • nameKey

      @NotNull public @NotNull String nameKey()
      Lang key of the setting's name.
    • descriptionKey

      @NotNull public @NotNull String descriptionKey()
      Lang key of the setting's one-line description.
    • toString

      public String toString()
      Overrides:
      toString in class Object