Skip to content

ConfigManager ​

com.jsmacrosce.jsmacros.core.config.ConfigManager

Manages registered configuration-option classes and the JSON data loaded for them.
Scripts can obtain the manager from JsMacros.getConfig():

js
const config = JsMacros.getConfig();  
Chat.log(config.configFile.getPath());

Constructors ​

new ConfigManager ​

new ConfigManager(Core<?, ?> runner, File configFolder, File macroFolder, Logger logger)#
Initializes the core option registration and loads configuration, attempting to create the supplied directories when missing. If the macro directory is initially missing, also attempts to create its index.js; directory and file creation are best-effort. Checked failures from configuration loading are wrapped in RuntimeException.

Parameters:

  • runner: runtime retained for option setup
  • configFolder: directory used to locate the options file
  • macroFolder: directory for macros
  • logger: logger for configuration operations

Fields ​

configFile ​

configFile: Fileread-only#
Configuration JSON file, named options.json under the constructor's configuration-directory argument.

configFolder ​

configFolder: Fileread-only#
Absolute configuration directory retained by this manager.

LOGGER ​

LOGGER: Loggerread-only#
Logger used for configuration operations.

macroFolder ​

macroFolder: Fileread-only#
Absolute macro directory retained by this manager.

optionClasses ​

optionClasses: Map<String, Class<?>>read-only#
Maps JSON root property names to registered option classes.

options ​

options: Map<Class<?>, Object>read-only#
Maps registered option classes to their loaded or default option values.

rawOptions ​

rawOptions: JsonObject#
Raw JSON data most recently read or built; initially null and not automatically synchronized with options.

TARGET_VERSION ​

static TARGET_VERSION: intread-only#
Schema version written to configuration data; this is not the JsMacros release version.

Methods ​

addOptions ​

addOptions(String key, Class<?> optionClass): void#
Registers an option class and loads its value, falling back to a new default instance if loading fails. Registration occurs before loading and is retained if loading fails. Only a duplicate JSON key is rejected; the same class may be registered under another key, replacing its value in options. A declared runner field is injected when present. Default construction requires an accessible public no-argument constructor.

Parameters:

  • key: JSON root property name; must not already be registered
  • optionClass: option class to register and load

backupConfig ​

backupConfig(): void#
Moves the current file to options.json.vN.bak, where N is the loaded config version, then attempts to save current state. Moving can fail with IOException; saveConfig catches save failures.

getOptions ​

getOptions(Class<T> optionClass): T#
Returns the stored option value for a registered class; does not instantiate or reload it.

Parameters:

  • optionClass: class used as the option-value key

Type Parameters:

  • T: option value type
Returns: stored value, or null if absent or stored as null

loadConfig ​

loadConfig(): void#
Clears existing instances and reloads them from disk, converting older data when supported. Loading failures caught per option fall back to that option's defaults; an InvocationTargetException or NoSuchMethodException escaping conversion or default construction instead resets all registered options to defaults. If no method named fromV followed by the loaded version exists, Gson loads the option instead of using the outer fallback. Backs up when the loaded version differs.

loadDefaults ​

loadDefaults(): void#
Instantiates defaults for registered option classes and resets raw data to an empty current-version JSON object. Does not inject runner fields or write the config file.

reloadRawConfigFromFile ​

reloadRawConfigFromFile(): void#
Reads raw JSON and its schema version without rebuilding typed option values; if the file is missing, builds registered defaults. A missing version is treated as 1. Read, parse, and default-construction failures propagate.

saveConfig ​

saveConfig(): void#
Attempts to serialize registered options into the raw JSON data and write it to the config file. Exceptions during serialization or writing are logged and not propagated.