Class YamlConfiguration

All Implemented Interfaces:
Configuration, ConfigurationSection

public class YamlConfiguration
extends FileConfiguration
An implementation of Configuration which saves all files in Yaml. Note that this implementation is not synchronized.
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
    • COMMENT_PREFIX

      protected static final java.lang.String COMMENT_PREFIX
      See Also:
      Constant Field Values
    • BLANK_CONFIG

      protected static final java.lang.String BLANK_CONFIG
      See Also:
      Constant Field Values
    • yamlOptions

      private final org.yaml.snakeyaml.DumperOptions yamlOptions
    • loaderOptions

      private final org.yaml.snakeyaml.LoaderOptions loaderOptions
    • yamlRepresenter

      private final org.yaml.snakeyaml.representer.Representer yamlRepresenter
    • yaml

      private final org.yaml.snakeyaml.Yaml yaml
  • Constructor Details

    • YamlConfiguration

      public YamlConfiguration()
  • Method Details

    • saveToString

      @NotNull public @NotNull java.lang.String saveToString()
      Description copied from class: FileConfiguration
      Saves this FileConfiguration to a string, and returns it.
      Specified by:
      saveToString in class FileConfiguration
      Returns:
      String containing this configuration.
    • loadFromString

      public void loadFromString​(@NotNull @NotNull java.lang.String contents) throws InvalidConfigurationException
      Description copied from class: FileConfiguration
      Loads this FileConfiguration from the specified string, as opposed to from file.

      All the values contained within this configuration will be removed, leaving only settings and defaults, and the new values will be loaded from the given string.

      If the string is invalid in any way, an exception will be thrown.

      Specified by:
      loadFromString in class FileConfiguration
      Parameters:
      contents - Contents of a Configuration to load.
      Throws:
      InvalidConfigurationException - Thrown if the specified string is invalid.
    • convertMapsToSections

      protected void convertMapsToSections​(@NotNull @NotNull java.util.Map<?,​?> input, @NotNull @NotNull ConfigurationSection section)
    • parseHeader

      @NotNull protected @NotNull java.lang.String parseHeader​(@NotNull @NotNull java.lang.String input)
    • buildHeader

      @NotNull protected @NotNull java.lang.String buildHeader()
      Description copied from class: FileConfiguration
      Compiles the header for this FileConfiguration and returns the result.

      This will use the header from FileConfiguration.options() -> FileConfigurationOptions.header(), respecting the rules of FileConfigurationOptions.copyHeader() if set.

      Specified by:
      buildHeader in class FileConfiguration
      Returns:
      Compiled header
    • options

      @NotNull public @NotNull YamlConfigurationOptions options()
      Description copied from interface: Configuration
      Gets the ConfigurationOptions for this Configuration.

      All setters through this method are chainable.

      Specified by:
      options in interface Configuration
      Overrides:
      options in class FileConfiguration
      Returns:
      Options for this configuration
    • loadConfiguration

      @NotNull public static @NotNull YamlConfiguration loadConfiguration​(@NotNull @NotNull java.io.File file)
      Creates a new YamlConfiguration, loading from the given file.

      Any errors loading the Configuration will be logged and then ignored. If the specified input is not a valid config, a blank config will be returned.

      The encoding used may follow the system dependent default.

      Parameters:
      file - Input file
      Returns:
      Resulting configuration
      Throws:
      java.lang.IllegalArgumentException - Thrown if file is null
    • loadConfiguration

      @NotNull public static @NotNull YamlConfiguration loadConfiguration​(@NotNull @NotNull java.io.Reader reader)
      Creates a new YamlConfiguration, loading from the given reader.

      Any errors loading the Configuration will be logged and then ignored. If the specified input is not a valid config, a blank config will be returned.

      Parameters:
      reader - input
      Returns:
      resulting configuration
      Throws:
      java.lang.IllegalArgumentException - Thrown if stream is null