Interface Preference<T>

Type Parameters:
T - the preference value type
All Known Subinterfaces:
Preference.Numeric<T>

@Experimental @AvailableSince("1.3") public interface Preference<T>
Represents a player preference with a default value and type.

Preferences are plugin-specific, typed values that can be stored persistently for players. Implementations must provide the owning plugin, a unique displayName, a default value, and a type for serialization.

Since:
1.3
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    Builder for constructing preference instances with a fluent API.
    static interface 
    A preference for numeric values with optional range constraints.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Preference.Builder<T>
    builder(Plugin plugin, String name, PreferenceType<T> type, T defaultValue)
    Creates a new preference builder for constructing preferences.
    default @Nullable net.kyori.adventure.text.Component
    Gets the description for this preference shown in UI.
    default net.kyori.adventure.text.Component
    Gets the display displayName for this preference shown in UI.
    Gets the default value for this preference.
    default net.kyori.adventure.key.Key
    key()
    Gets the namespaced key for this preference.
    Gets the displayName of this preference.
    Gets the plugin displayName that owns this preference.
    Gets the type used for serializing/deserializing this preference.
  • Method Details

    • plugin

      @AvailableSince("1.3") Plugin plugin()
      Gets the plugin displayName that owns this preference.
      Returns:
      the owning plugin displayName
    • name

      @AvailableSince("1.3") String name()
      Gets the displayName of this preference.
      Returns:
      the preference displayName
    • getDefault

      @AvailableSince("1.3") T getDefault()
      Gets the default value for this preference.
      Returns:
      the default value
    • type

      @AvailableSince("1.3") PreferenceType<T> type()
      Gets the type used for serializing/deserializing this preference.
      Returns:
      the preference type
    • key

      @AvailableSince("1.3") default net.kyori.adventure.key.Key key()
      Gets the namespaced key for this preference.
      Returns:
      the preference key
    • displayName

      @AvailableSince("1.3") default net.kyori.adventure.text.Component displayName()
      Gets the display displayName for this preference shown in UI.

      Defaults to a text component of name().

      Returns:
      the display displayName component
    • description

      @AvailableSince("1.3") @Nullable default @Nullable net.kyori.adventure.text.Component description()
      Gets the description for this preference shown in UI.

      Defaults to null (no description).

      Returns:
      the description component, or null if none
    • builder

      @AvailableSince("1.3") static <T> Preference.Builder<T> builder(Plugin plugin, String name, PreferenceType<T> type, T defaultValue)
      Creates a new preference builder for constructing preferences.
      Type Parameters:
      T - the preference value type
      Parameters:
      plugin - the owning plugin
      name - the preference displayName
      type - the preference type
      defaultValue - the default value
      Returns:
      a new preference builder