Choose a file format

Pick between whole-file syncing and key-by-key syncing for each settings file, with the built-in WHOLE_FILE, PROPERTIES and KEY_VALUE formats compared.

Last updated

Steps

The format you give a file decides whether Settings Saver treats it as one blob or as separate settings. This guide helps you pick one for each file.

Prerequisites#

Whole file or key by key#

A SettingsFileFormat reads a file into a flat key -> value map. With a real format, Settings Saver compares the file key by key. Without one, the whole file is a single value.

Whole file (WHOLE_FILE, the default) Key by key (any other format)
Works for any UTF-8 text file files the format can parse
Comments and layout kept exactly up to the format (PROPERTIES drops comments)
What a save writes to the profile the whole file only the settings the player changed
Two instances change different settings the newest save wins, the other change is lost both changes are kept
Players can exclude single settings no, only the whole file yes
Loading a profile replaces the instance's file merges the profile's values over the instance's file
Fixes between versions see the file as one value under the key content see every key

Use key by key whenever a format fits. Use whole file for files with free-form content, or when keeping the file's comments matters more than merging.

The built-in formats#

All three are constants of SettingsFileFormats. Each is a stateless singleton that any number of files and mods can share.

WHOLE_FILE#

The whole file as one value under the key content (SettingsFileFormats.WHOLE_FILE_KEY), written back character for character. It is what .file(path) and .directory(path) use.

.file("config/mymod.json")                                    // the same as:
.file("config/mymod.json", SettingsFileFormats.WHOLE_FILE)

A player who excludes the key content for your mod turns saving of such a file off.

PROPERTIES#

Simple key=value lines:

config/mymod.properties
# My Mod settings
renderDistance = 12
showHud=true
.file("config/mymod.properties", SettingsFileFormats.PROPERTIES)

Reading:

Writing: one key=value line per setting, in order.

KEY_VALUE#

Minecraft's key:value lines, as in options.txt:

config/mymod.txt
renderDistance:12
serverAddress:play.example.com:25565
.file("config/mymod.txt", SettingsFileFormats.KEY_VALUE)

Reading:

Writing: one key:value line per setting, in order.

Which one for my file#

Your file Use
key=value lines PROPERTIES
key:value lines KEY_VALUE
[section] headers with key = value lines your own format (complete example)
TOML, JSON, YAML your own format that flattens nested keys, or WHOLE_FILE
free text, scripts, lists WHOLE_FILE
a file whose comments must survive WHOLE_FILE

Next steps#