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 Details

    • getDefaultFiles

      FilePack getDefaultFiles()
      The defaults read from the jar.
      Returns:
      the default files
    • init

      void init()
      Reads the defaults out of the jar and writes any file that is missing on disk.
    • loadVersion

      String loadVersion()
      Reads the version from the config file on disk.
      Returns:
      the version string
    • loadFiles

      FilePack loadFiles(FilePack currentFiles)
      Reads every file from disk, merging each over the matching current one.
      Parameters:
      currentFiles - the files to merge over, or null to merge over the defaults
      Returns:
      the loaded set
    • loadAndMergeConfig

      Config loadAndMergeConfig(FilePack currentFiles)
      Reads config.yml only, which is needed before the rest so the language is known.
      Parameters:
      currentFiles - the files to merge over, or null to merge over the defaults
      Returns:
      the loaded config
    • 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 language
      localizations - the localizations to merge over
      merge - whether to merge over the defaults, or take the file as-is
      Returns:
      the loaded localizations, keyed by locale name
    • loadOrDefault

      <T> T loadOrDefault(String path, T defaultFile, BinaryOperator<T> mergeOperator)
      Reads one file and merges it over the given default.
      Type Parameters:
      T - the file type
      Parameters:
      path - the file path inside the plugin folder
      defaultFile - the value to merge over
      mergeOperator - merges the default with what was read
      Returns:
      the merged value, or the default if the file is missing
    • loadOrDefault

      <T> T loadOrDefault(String path, T defaultFile, BinaryOperator<T> mergeOperator, boolean merge)
      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 folder
      defaultFile - the value to merge over
      mergeOperator - merges the default with what was read
      merge - whether to merge, or return the file unchanged
      Returns:
      the resulting value, or the default if the file is missing
    • loadFromResource

      <T> T loadFromResource(String path, Class<T> type)
      Reads a file bundled in the jar.
      Type Parameters:
      T - the file type
      Parameters:
      path - the resource path
      type - the type to parse into
      Returns:
      the parsed file
      Throws:
      FileLoadException - if the resource is missing or malformed
    • load

      <T> Optional<T> load(Path pathToFile, T defaultFile)
      Reads a single file from disk without merging.
      Type Parameters:
      T - the file type
      Parameters:
      pathToFile - the file to read
      defaultFile - supplies the type to parse into, and is rewritten if the file is empty
      Returns:
      the parsed file, or empty if it was blank