Class ModSettings

java.lang.Object
forgottentowns.mod.api.ModSettings

public final class ModSettings extends Object
Startup-only typed reader that tracks which captured settings a mod attempts to consume. Each read removes its key from the unread set before validation, including a read that throws. Call requireAllRead() after successful registration reads to reject unknown supplied keys. This reader is mutable and is intended for one registration thread; values are copied shallowly.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Copies settings for one registration.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    decimal(String key, double fallback, double min, double max)
    Reads a finite numeric value, converting a Number through its doubleValue method.
    boolean
    flag(String key, boolean fallback)
    Reads a boolean.
    ids(String key, String fallback)
    Reads a nonempty comma-separated set of lowercase content identifiers without trimming entries.
    int
    integer(String key, int fallback, int min, int max)
    Reads a bounded integer.
    void
    Rejects unconsumed keys so spelling mistakes cannot silently keep a default.
    text(String key, String fallback)
    Reads a nonblank identifier or other short configuration string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ModSettings

      public ModSettings(Map<String,Object> values)
      Copies settings for one registration.
      Parameters:
      values - settings obtained from the mod context; subsequent map mutations are not observed
      Throws:
      NullPointerException - if values, any key, or any value is null
  • Method Details

    • integer

      public int integer(String key, int fallback, int min, int max)
      Reads a bounded integer.
      Parameters:
      key - nonnull setting identity, consumed even when validation fails
      fallback - value when absent, validated against the same bounds
      min - inclusive minimum
      max - inclusive maximum
      Returns:
      validated integer
      Throws:
      IllegalArgumentException - if the value is not numeric, is fractional or nonfinite, or lies outside the bounds
      NullPointerException - if key is null
    • decimal

      public double decimal(String key, double fallback, double min, double max)
      Reads a finite numeric value, converting a Number through its doubleValue method.
      Parameters:
      key - nonnull setting identity, consumed even when validation fails
      fallback - value when absent, validated against the same bounds
      min - inclusive minimum; callers must supply an ordered, non-NaN range
      max - inclusive maximum; callers must supply an ordered, non-NaN range
      Returns:
      validated number
      Throws:
      IllegalArgumentException - if not a finite number in range
      NullPointerException - if key is null
    • flag

      public boolean flag(String key, boolean fallback)
      Reads a boolean.
      Parameters:
      key - nonnull setting identity, consumed even when validation fails
      fallback - value when absent
      Returns:
      validated flag
      Throws:
      IllegalArgumentException - if the value is not boolean
      NullPointerException - if key is null
    • text

      public String text(String key, String fallback)
      Reads a nonblank identifier or other short configuration string.
      Parameters:
      key - nonnull setting identity, consumed even when validation fails
      fallback - value when absent, subject to the same validation as a supplied setting
      Returns:
      the accepted string unchanged, nonblank, at most 256 characters, and already equal to its String.trim() result; this method does not trim input
      Throws:
      IllegalArgumentException - if the value or fallback is blank, too long, not text, or has leading/trailing characters that String.trim() would remove
      NullPointerException - if key is null
    • ids

      public Set<String> ids(String key, String fallback)
      Reads a nonempty comma-separated set of lowercase content identifiers without trimming entries. Every identifier must match [a-z][a-z0-9_:]*; the complete text also satisfies text(java.lang.String, java.lang.String).
      Parameters:
      key - nonnull setting identity, consumed even when validation fails
      fallback - comma-separated defaults, validated like a supplied value
      Returns:
      immutable identifier set whose iteration order is unspecified
      Throws:
      IllegalArgumentException - if text validation fails or an identifier is empty, duplicated, contains whitespace, or does not match the identifier pattern
      NullPointerException - if key is null
    • requireAllRead

      public void requireAllRead()
      Rejects unconsumed keys so spelling mistakes cannot silently keep a default.
      Throws:
      IllegalArgumentException - if any supplied setting was not read