Package dev.xichil.settingssaver.api.v1
Settings Saver keeps a player's settings in named profiles outside any one game directory, and syncs
them into every instance (modpack, launcher profile, Minecraft version) that uses the same profile. Out of the box it
handles Minecraft's own options.txt. This package lets any other mod have its own settings files
saved, loaded and synced the same way, with Settings Saver as an optional dependency: when Settings
Saver isn't installed, the mod runs exactly as it did before.
Getting started
- Compile against the API with
compileOnly("dev.xichil.settingssaver:settingssaver-api:<version>"). Never bundle, shade or jar-in-jar it: Settings Saver's own jar ships these classes, and a second copy on the class path would split them in two. - Implement
SettingsSaverPluginin a class of its own and describe your files with aModSettings:public final class MyModSettingsSaver implements SettingsSaverPlugin { public void register(SettingsSaverRegistrar registrar) { registrar.register(ModSettings.builder("mymod", "My Mod", "2.1.0") .file("config/mymod.properties", SettingsFileFormats.PROPERTIES) .excludedByDefault("windowX", "windowY") .build()); } } - List that class, by its fully qualified name, in
META-INF/services/dev.xichil.settingssaver.api.v1.SettingsSaverPlugininside your jar.
Settings Saver finds the plugin with ServiceLoader. When Settings Saver is absent, nobody reads
that service file, so the plugin class, which should be the only class of your mod that references this package, is
never loaded and can't fail with NoClassDefFoundError. If you'd rather register from your own init
code, see SettingsSaverMods.
What Settings Saver does with a registration
- Off unless chosen. A mod's settings are only saved into a profile when the player turns the mod on for that profile, or when the mod asked for saved by default and the player hasn't turned it off.
- Key by key. Each file is read through a
SettingsFileFormatinto a flatkey -> valuemap. Only settings the player actually changed are written into the profile, keys can be excluded one by one, and loading a profile merges its values over the instance's file instead of replacing it. With the defaultSettingsFileFormats.WHOLE_FILEthe file is a single value and is copied as a whole. - Across versions. The profile records which mod version and which Minecraft DataVersion its copy was saved
in.
SettingsFixes convert the settings when a profile written by one version is used by another. - Storage. A profile keeps the mod's files under
profiles/<profile>/<mod id>/<path>, next to amodule.txtwith the version record, written with the same format as the file in the game directory.
Threads and errors
Your plugin's register runs once, on the thread that launches the game. Your formats, fixes and mergers
are called later, from whichever thread is syncing: Settings Saver's background watcher, the menu's Save and Load
actions, or the shutdown hook. Keep them stateless (or thread-safe), quick, and free of side effects. Settings Saver
never lets a mod's code break the game: a registration it refuses, a plugin that throws, and a fix or merger that
throws are all logged and skipped, and the rest of the mod's settings, and every other mod's, still sync.
Compatibility
Nothing in this package references Minecraft, a mod loader or Settings Saver's internals; it is plain Java 8, so
one integration works on every Minecraft version and loader Settings Saver supports. The package only ever changes
compatibly: members may be added, none are removed or change meaning. A breaking change would come as a new
v2 package next to this one, and Settings Saver would keep serving v1.
docs/API.md in Settings Saver's repository walks through the same steps with build snippets for each
loader.
- See Also:
-
ClassDescriptionEverything Settings Saver needs to know about one mod's settings: which files and directories hold them, how each file is read, whether profiles save them without being asked, which keys are left out by default, how changes are merged, and the fixes that convert them between versions of the mod and of Minecraft.Builds a
ModSettings; get one fromModSettings.builder(String, String, String).One registered path: a settings file, or a directory whose files, at any depth, are each synced like a registered file with the directory's format.A fix registered withModSettings.Builder.minecraftFix(String, SettingsFix)orModSettings.Builder.minecraftFix(int, SettingsFix): applies from a Minecraft version on, given either as a release id or as a DataVersion (exactly one of the two is set).A fix registered withModSettings.Builder.modVersionFix(String, SettingsFix): applies from mod versionModSettings.ModVersionFix.version()on.How one of your settings files is read into a flat, orderedkey -> valuemap and written back.Ready-madeSettingsFileFormats for the common kinds of settings files.One reversible change to the format of your settings, like one of Minecraft's DataFixers, but able to go back as well as forward.Decides how the settings a player changed in one instance go into the copy a profile keeps.Registration from your own code, for mods that would rather not use theSettingsSaverPluginservice file.A mod's integration with Settings Saver: the class Settings Saver calls to learn which of the mod's files it should sync.Takes mods' settings registrations.