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
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 setupconfigFolder: directory used to locate the options filemacroFolder: directory for macroslogger: logger for configuration operations
Fields
configFile
configFolder
LOGGER
macroFolder
optionClasses
options
rawOptions
rawOptions: JsonObject#Raw JSON data most recently read or built; initially
null and not automatically synchronized with options.TARGET_VERSION
Schema version written to configuration data; this is not the JsMacros release version.
Methods
addOptions
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 registeredoptionClass: 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
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.