Package forgottentowns.mod.api
Class ModSettings
java.lang.Object
forgottentowns.mod.api.ModSettings
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
ConstructorsConstructorDescriptionModSettings(Map<String, Object> values) Copies settings for one registration. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReads a finite numeric value, converting a Number through its doubleValue method.booleanReads a boolean.Reads a nonempty comma-separated set of lowercase content identifiers without trimming entries.intReads a bounded integer.voidRejects unconsumed keys so spelling mistakes cannot silently keep a default.Reads a nonblank identifier or other short configuration string.
-
Constructor Details
-
ModSettings
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
Reads a bounded integer.- Parameters:
key- nonnull setting identity, consumed even when validation failsfallback- value when absent, validated against the same boundsmin- inclusive minimummax- inclusive maximum- Returns:
- validated integer
- Throws:
IllegalArgumentException- if the value is not numeric, is fractional or nonfinite, or lies outside the boundsNullPointerException- if key is null
-
decimal
Reads a finite numeric value, converting a Number through its doubleValue method.- Parameters:
key- nonnull setting identity, consumed even when validation failsfallback- value when absent, validated against the same boundsmin- inclusive minimum; callers must supply an ordered, non-NaN rangemax- inclusive maximum; callers must supply an ordered, non-NaN range- Returns:
- validated number
- Throws:
IllegalArgumentException- if not a finite number in rangeNullPointerException- if key is null
-
flag
Reads a boolean.- Parameters:
key- nonnull setting identity, consumed even when validation failsfallback- value when absent- Returns:
- validated flag
- Throws:
IllegalArgumentException- if the value is not booleanNullPointerException- if key is null
-
text
Reads a nonblank identifier or other short configuration string.- Parameters:
key- nonnull setting identity, consumed even when validation failsfallback- 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 thatString.trim()would removeNullPointerException- if key is null
-
ids
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 satisfiestext(java.lang.String, java.lang.String).- Parameters:
key- nonnull setting identity, consumed even when validation failsfallback- 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 patternNullPointerException- 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
-