Interface Preference.Numeric<T extends Number & Comparable<T>>

Type Parameters:
T - the numeric type (must be comparable)
All Superinterfaces:
Preference<T>
Enclosing interface:
Preference<T>

@Experimental @AvailableSince("1.3") public static interface Preference.Numeric<T extends Number & Comparable<T>> extends Preference<T>
A preference for numeric values with optional range constraints.

This interface extends Preference to provide minimum and maximum bounds for numeric values. Values outside the specified range can be rejected or clamped to the valid range.

Since:
1.3
  • Method Details

    • min

      @AvailableSince("1.3") @Nullable T min()
      Gets the minimum allowed value for this preference.
      Returns:
      the minimum value, or null if unbounded
    • max

      @AvailableSince("1.3") @Nullable T max()
      Gets the maximum allowed value for this preference.
      Returns:
      the maximum value, or null if unbounded
    • isInRange

      @AvailableSince("1.3") default boolean isInRange(T value)
      Checks if a value is within the allowed range.
      Parameters:
      value - the value to check
      Returns:
      true if the value is within bounds, false otherwise
    • clamp

      @AvailableSince("1.3") default T clamp(T value)
      Clamps a value to the allowed range.

      If the value is below the minimum, returns the minimum. If the value is above the maximum, returns the maximum. Otherwise returns the value unchanged.

      Parameters:
      value - the value to clamp
      Returns:
      the clamped value
    • builder

      @AvailableSince("1.3") static <T extends Number & Comparable<T>> Preference.Numeric.NumericBuilder<T> builder(Plugin plugin, String name, PreferenceType<T> type, T defaultValue)
      Creates a new numeric preference builder.
      Type Parameters:
      T - the numeric type
      Parameters:
      plugin - the owning plugin
      name - the preference name
      type - the preference type
      defaultValue - the default value
      Returns:
      a new numeric preference builder