Interface FileLoader
public interface FileLoader
Reads config files from disk and merges them over the defaults shipped in the jar, so a
user file only has to carry the keys it actually overrides.
-
Method Summary
Modifier and TypeMethodDescriptionThe defaults read from the jar.voidinit()Reads the defaults out of the jar and writes any file that is missing on disk.<T> Optional<T> Reads a single file from disk without merging.loadAndMergeConfig(FilePack currentFiles) Reads config.yml only, which is needed before the rest so the language is known.Reads every file from disk, merging each over the matching current one.<T> TloadFromResource(String path, Class<T> type) Reads a file bundled in the jar.loadLocalizationFiles(Config config, Map<String, Localization> localizations, boolean merge) Reads every localization file present on disk plus the shipped languages.<T> TloadOrDefault(String path, T defaultFile, BinaryOperator<T> mergeOperator) Reads one file and merges it over the given default.<T> TloadOrDefault(String path, T defaultFile, BinaryOperator<T> mergeOperator, boolean merge) Reads one file, either merging it over the given default or taking it as-is.Reads the version from the config file on disk.
-
Method Details
-
getDefaultFiles
-
init
void init()Reads the defaults out of the jar and writes any file that is missing on disk. -
loadVersion
-
loadFiles
-
loadAndMergeConfig
-
loadLocalizationFiles
Map<String, Localization> loadLocalizationFiles(Config config, Map<String, Localization> localizations, boolean merge) Reads every localization file present on disk plus the shipped languages.- Parameters:
config- supplies the server default languagelocalizations- the localizations to merge overmerge- whether to merge over the defaults, or take the file as-is- Returns:
- the loaded localizations, keyed by locale name
-
loadOrDefault
Reads one file and merges it over the given default.- Type Parameters:
T- the file type- Parameters:
path- the file path inside the plugin folderdefaultFile- the value to merge overmergeOperator- merges the default with what was read- Returns:
- the merged value, or the default if the file is missing
-
loadOrDefault
Reads one file, either merging it over the given default or taking it as-is.- Type Parameters:
T- the file type- Parameters:
path- the file path inside the plugin folderdefaultFile- the value to merge overmergeOperator- merges the default with what was readmerge- whether to merge, or return the file unchanged- Returns:
- the resulting value, or the default if the file is missing
-
loadFromResource
Reads a file bundled in the jar.- Type Parameters:
T- the file type- Parameters:
path- the resource pathtype- the type to parse into- Returns:
- the parsed file
- Throws:
FileLoadException- if the resource is missing or malformed
-
load
Reads a single file from disk without merging.- Type Parameters:
T- the file type- Parameters:
pathToFile- the file to readdefaultFile- supplies the type to parse into, and is rewritten if the file is empty- Returns:
- the parsed file, or empty if it was blank
-