Register files and directories

Tell Settings Saver which of your mod's settings files and folders to sync, with the path rules and what happens to files that appear later.

Last updated

Steps

This guide shows how to register one file, several files and whole directories, and which paths are accepted.

Prerequisites#

The four methods#

All four are on ModSettings.Builder. Call them as often as you need, at least once in total.

Call Syncs How
.file(path) one file as a whole (WHOLE_FILE)
.file(path, format) one file key by key, read with format
.directory(path) every file in a folder, at any depth each as a whole
.directory(path, format) every file in a folder, at any depth each key by key, read with format

"As a whole" and "key by key" are explained in Choose a file format.

Steps#

1. Register single files#

ModSettings.builder("mymod", "My Mod", "2.1.0")
        .file("config/mymod.properties", SettingsFileFormats.PROPERTIES)   // key by key
        .file("config/mymod-notes.txt")                                    // as a whole
        .build();

A file doesn't have to exist yet. Until it does, there is nothing to save. An instance without the file gets the profile's copy when it starts.

2. Register a directory for one-file-per-thing settings#

Use a directory when your mod keeps one file per server, per waypoint set or per preset:

ModSettings.builder("mymod", "My Mod", "2.1.0")
        .directory("config/mymod/waypoints")                                // each file as a whole
        .directory("config/mymod/presets", SettingsFileFormats.PROPERTIES)  // each file key by key
        .build();

What a directory does:

3. Follow the path rules#

Paths are relative to the game directory, the instance folder that holds options.txt.

Path you pass Result
"config/mymod.toml" accepted
".\\config\\mymod.toml" (the Java string for .\config\mymod.toml) accepted, stored as config/mymod.toml
"config//mymod.toml" accepted, stored as config/mymod.toml
"config/mymod/" (trailing slash, for a directory) accepted, stored as config/mymod
"/home/alex/mymod.toml" rejected: absolute
"C:/mymod.toml" rejected: contains :
"../shared/mymod.toml" rejected: .. leaves the game directory
"" rejected: empty
the same path twice for one mod rejected

A rejected path throws IllegalArgumentException from the builder call, in your code, with a message that says what is wrong:

Invalid path '../x': it must be relative to the game directory and stay inside it

build() throws the same exception when no file or directory was added:

mymod: register at least one file or directory

4. Avoid paths another mod already syncs#

These checks happen when you register, because they depend on the other mods installed. They don't throw. Settings Saver logs a warning and ignores your whole registration when:

The warning names the path and who owns it. See Fix an integration that doesn't sync.

Where the files go in a profile#

Each profile stores your files under your mod id, at the same relative path:

In the game directory In the store
config/mymod.properties profiles/<profile>/mymod/config/mymod.properties
config/mymod/waypoints/home.json profiles/<profile>/mymod/config/mymod/waypoints/home.json
profiles/<profile>/mymod/module.txt (written by Settings Saver: the versions the settings were saved in)

The profile's copy is written with the same format as the file in the game directory.

Limits#

Next steps#