Class ConfigFile

java.lang.Object
fr.robie.machineengine.api.config.ConfigFile
All Implemented Interfaces:
ConfigValues

public final class ConfigFile extends Object implements ConfigValues
A YAML settings file read through typed ConfigKeys.

Loading never fails the plugin and never loses what the owner wrote:

  • a missing file is created from the ConfigSpec, with its header and comments;
  • a missing key is added with its default and comment, and the file is saved;
  • an invalid value logs a warning and uses the default (a clamped number out of range uses the nearest bound); the file keeps the owner's text;
  • keys the spec does not know are kept;
  • a file that cannot be parsed is not touched: defaults are used (or, on a reload, the old values).
The file is only saved when something was added, so an up-to-date file is never reformatted.
  • Method Details

    • load

      @NotNull public static @NotNull ConfigFile load(@NotNull @NotNull Path file, @NotNull @NotNull ConfigSpec spec, @NotNull @NotNull Logger logger)
      Loads file, creating or completing it.
    • load

      @NotNull public static @NotNull ConfigFile load(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull String fileName, @NotNull @NotNull ConfigSpec spec)
      Loads fileName in the plugin's data folder.
    • get

      @NotNull public <T> T get(@NotNull @NotNull ConfigKey<T> key)
      Description copied from interface: ConfigValues
      The value of key: the file's if it is valid, else the key's default.
      Specified by:
      get in interface ConfigValues
    • reload

      @NotNull public @NotNull ConfigLoadResult reload()
      Reads the file again; restart-only keys keep their value. Also adds keys that went missing.
    • file

      @NotNull public @NotNull Path file()
    • spec

      @NotNull public @NotNull ConfigSpec spec()