Class YamlConfiguration
- All Implemented Interfaces:
Configuration
,ConfigurationSection
public class YamlConfiguration extends FileConfiguration
Configuration
which saves all files in Yaml.
Note that this implementation is not synchronized.-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
BLANK_CONFIG
protected static java.lang.String
COMMENT_PREFIX
private org.yaml.snakeyaml.LoaderOptions
loaderOptions
private static org.apache.logging.log4j.Logger
logger
private org.yaml.snakeyaml.Yaml
yaml
private org.yaml.snakeyaml.DumperOptions
yamlOptions
private org.yaml.snakeyaml.representer.Representer
yamlRepresenter
Fields inherited from class org.bukkit.configuration.MemoryConfiguration
defaults, options
Fields inherited from class org.bukkit.configuration.MemorySection
map
-
Constructor Summary
Constructors Constructor Description YamlConfiguration()
-
Method Summary
Modifier and Type Method Description protected @NotNull java.lang.String
buildHeader()
Compiles the header for thisFileConfiguration
and returns the result.protected void
convertMapsToSections(@NotNull java.util.Map<?,?> input, @NotNull ConfigurationSection section)
static @NotNull YamlConfiguration
loadConfiguration(@NotNull java.io.File file)
Creates a newYamlConfiguration
, loading from the given file.static @NotNull YamlConfiguration
loadConfiguration(@NotNull java.io.Reader reader)
Creates a newYamlConfiguration
, loading from the given reader.void
loadFromString(@NotNull java.lang.String contents)
Loads thisFileConfiguration
from the specified string, as opposed to from file.@NotNull YamlConfigurationOptions
options()
Gets theConfigurationOptions
for thisConfiguration
.protected @NotNull java.lang.String
parseHeader(@NotNull java.lang.String input)
@NotNull java.lang.String
saveToString()
Saves thisFileConfiguration
to a string, and returns it.Methods inherited from class org.bukkit.configuration.file.FileConfiguration
load, load, load, save, save
Methods inherited from class org.bukkit.configuration.MemoryConfiguration
addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaults
Methods inherited from class org.bukkit.configuration.MemorySection
contains, contains, createPath, createPath, createSection, createSection, get, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getConfigurationSection, getCurrentPath, getDefault, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getName, getObject, getObject, getRoot, getSerializable, getSerializable, getShortList, getString, getString, getStringList, getValues, isBoolean, isConfigurationSection, isDouble, isInt, isList, isLong, isPrimitiveWrapper, isSet, isString, mapChildrenKeys, mapChildrenValues, set, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.bukkit.configuration.ConfigurationSection
contains, contains, createSection, createSection, get, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getConfigurationSection, getCurrentPath, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getName, getObject, getObject, getRoot, getSerializable, getSerializable, getShortList, getString, getString, getStringList, getValues, isBoolean, isConfigurationSection, isDouble, isInt, isList, isLong, isSet, isString, set
-
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 thisFileConfiguration
to a string, and returns it.- Specified by:
saveToString
in classFileConfiguration
- Returns:
- String containing this configuration.
-
loadFromString
public void loadFromString(@NotNull @NotNull java.lang.String contents) throws InvalidConfigurationExceptionDescription copied from class:FileConfiguration
Loads thisFileConfiguration
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 classFileConfiguration
- 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 thisFileConfiguration
and returns the result.This will use the header from
FileConfiguration.options()
->FileConfigurationOptions.header()
, respecting the rules ofFileConfigurationOptions.copyHeader()
if set.- Specified by:
buildHeader
in classFileConfiguration
- Returns:
- Compiled header
-
options
Description copied from interface:Configuration
Gets theConfigurationOptions
for thisConfiguration
.All setters through this method are chainable.
- Specified by:
options
in interfaceConfiguration
- Overrides:
options
in classFileConfiguration
- Returns:
- Options for this configuration
-
loadConfiguration
@NotNull public static @NotNull YamlConfiguration loadConfiguration(@NotNull @NotNull java.io.File file)Creates a newYamlConfiguration
, 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 newYamlConfiguration
, 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
-