-
-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration Class
Bizarre Cube edited this page Aug 14, 2026
·
2 revisions
A configuration is an ordinary class annotated with @AutoConfig. Requirements:
- Public no-argument constructor — used to produce the default values.
- Only non-static, non-
transientfields are taken into account.
-
ConfigHolder.register(Class)— registers the class (cached; calling it again returns the same holder) and immediately loads the config from disk. -
holder.get()— the current configuration instance. -
holder.load()— re-read the file (if missing, a file with default values is created). -
holder.save()— write to JSON and invokeonSavelisteners. -
holder.reset()— reset values to their defaults. -
holder.onSave(Consumer)— add a listener invoked after saving. -
holder.snapshot()— a JSON snapshot of the current state.
ConfigHolder<ExampleConfig> holder =
ConfigHolder.register(ExampleConfig.class)
.onSave(cfg -> System.out.println("Saved!")); File: config/<name>.json. Serialized with Gson using pretty-printing. Fields of type Component (and lists of Component) are not stored in JSON — they are meant for display only.