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 ClassesModifier and TypeInterfaceDescriptionstatic final classBuilder for constructing preference instances with a fluent API.static interfacePreference.Numeric<T extends Number & Comparable<T>>A preference for numeric values with optional range constraints. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.ComponentGets the description for this preference shown in UI.default net.kyori.adventure.text.ComponentGets the display displayName for this preference shown in UI.Gets the default value for this preference.default net.kyori.adventure.key.Keykey()Gets the namespaced key for this preference.name()Gets the displayName of this preference.plugin()Gets the plugin displayName that owns this preference.type()Gets the type used for serializing/deserializing this preference.
-
Method Details
-
plugin
Gets the plugin displayName that owns this preference.- Returns:
- the owning plugin displayName
-
name
Gets the displayName of this preference.- Returns:
- the preference displayName
-
getDefault
Gets the default value for this preference.- Returns:
- the default value
-
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 pluginname- the preference displayNametype- the preference typedefaultValue- the default value- Returns:
- a new preference builder
-