Skip to content

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-transient fields are taken into account.

Registration and Lifecycle

  • 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 invoke onSave listeners.
  • 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!"));  

Storage

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.

Clone this wiki locally