Interface ConfigurationSection
- All Known Subinterfaces:
Configuration
- All Known Implementing Classes:
FileConfiguration,MemoryConfiguration,MemorySection,YamlConfiguration,YamlFile
Configuration- Author:
- Bukkit
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefault(String path, Object value) Sets the default value in the root at the given path as provided.booleanChecks if thisConfigurationSectioncontains the given path.createSection(String path) Creates an emptyConfigurationSectionat the specified path.createSection(String path, Map<?, ?> map) Creates aConfigurationSectionat the specified path, with specified values.Gets the requested Object by path.Gets the requested Object by path, returning a default value if not found.booleangetBoolean(String path) Gets the requested boolean by path.booleangetBoolean(String path, boolean def) Gets the requested boolean by path, returning a default value if not found.getBooleanList(String path) Gets the requested List of Boolean by path.byteGets the requested byte by path.byteGets the requested byte by path, returning a default value if not found.getByteList(String path) Gets the requested List of Byte by path.chargetCharacter(String path) Gets the requested char by path.chargetCharacter(String path, char def) Gets the requested char by path, returning a default value if not found.getCharacterList(String path) Gets the requested List of Character by path.Gets the requested ConfigurationSection by path.Gets the path of thisConfigurationSectionfrom its rootConfigurationdoubleGets the requested double by path.doubleGets the requested double by path, returning a default value if not found.getDoubleList(String path) Gets the requested List of Double by path.floatGets the requested float by path.floatGets the requested float by path, returning a default value if not found.getFloatList(String path) Gets the requested List of Float by path.intGets the requested int by path.intGets the requested int by path, returning a default value if not found.getIntegerList(String path) Gets the requested List of Integer by path.getKeys(boolean deep) Gets a set containing all keys in this section.List<?>Gets the requested List by path.List<?>Gets the requested List by path, returning a default value if not found.longGets the requested long by path.longGets the requested long by path, returning a default value if not found.getLongList(String path) Gets the requested List of Long by path.getMapList(String path) Gets the requested List of Maps by path.getMapValues(boolean deep) Gets a Map containing all keys and their values for this section.getName()Gets the name of this individualConfigurationSection, in the path.Gets the parentConfigurationSectionthat directly contains thisConfigurationSection.getRoot()Gets the rootConfigurationthat contains thisConfigurationSectionshortGets the requested short by path.shortGets the requested short by path, returning a default value if not found.getShortList(String path) Gets the requested List of Short by path.Gets the requested String by path.Gets the requested String by path, returning a default value if not found.getStringList(String path) Gets the requested List of String by path.getValues(boolean deep) Gets a Map containing all keys and their values for this section.booleanChecks if the specified path is a boolean.booleanChecks if the specified path is a byte.booleanisCharacter(String path) Checks if the specified path is a char.booleanisConfigurationSection(String path) Checks if the specified path is a ConfigurationSection.booleanChecks if the specified path is a double.booleanisEmpty()Gets if this configuration section is empty.booleanChecks if the specified path is a float.booleanChecks if the specified path is an int.booleanChecks if the specified path is a List.booleanChecks if the specified path is a long.booleanChecks if thisConfigurationSectionhas a value set for the given path.booleanChecks if the specified path is a short.booleanChecks if the specified path is a String.default voidRemoves the specified path if it exists.voidSets the specified path to the given value.intsize()Gets the size of this configuration section.
-
Method Details
-
getKeys
Gets a set containing all keys in this section.If deep is set to true, then this will contain all the keys within any child
ConfigurationSections (and their children, etc). These will be in a valid path notation for you to use.If deep is set to false, then this will contain only the keys of any direct children, and not their own children.
- Parameters:
deep- Whether or not to get a deep list, as opposed to a shallow list.- Returns:
- Set of keys contained within this ConfigurationSection.
-
getValues
Gets a Map containing all keys and their values for this section.If deep is set to true, then this will contain all the keys and values within any child
ConfigurationSections (and their children, etc). These keys will be in a valid path notation for you to use.If deep is set to false, then this will contain only the keys and values of any direct children, and not their own children.
- Parameters:
deep- Whether or not to get a deep list, as opposed to a shallow list.- Returns:
- Map of keys and values of this section.
-
getMapValues
Gets a Map containing all keys and their values for this section.If deep is set to true, then this will contain all the keys and values within any child
Maps (and their children, etc). These keys will be in a valid path notation for you to use.If deep is set to false, then this will contain only the keys and values of any direct children, and not their own children.
- Parameters:
deep- Whether or not to get a deep list, as opposed to a shallow list.- Returns:
- Map of keys and values of this section.
-
contains
Checks if thisConfigurationSectioncontains the given path.If the value for the requested path does not exist but a default value has been specified, this will return true.
- Parameters:
path- Path to check for existence.- Returns:
- True if this section contains the requested path, either via default or being set.
- Throws:
IllegalArgumentException- Thrown when path is null.
-
isSet
Checks if thisConfigurationSectionhas a value set for the given path.If the value for the requested path does not exist but a default value has been specified, this will still return false.
- Parameters:
path- Path to check for existence.- Returns:
- True if this section contains the requested path, regardless of having a default.
- Throws:
IllegalArgumentException- Thrown when path is null.
-
size
int size()Gets the size of this configuration section.- Returns:
- number of keys in this configuration section
-
isEmpty
boolean isEmpty()Gets if this configuration section is empty.- Returns:
- if there are no keys in this configuration section
-
getCurrentPath
String getCurrentPath()Gets the path of thisConfigurationSectionfrom its rootConfigurationFor any
Configurationthemselves, this will return an empty string.If the section is no longer contained within its root for any reason, such as being replaced with a different value, this may return null.
To retrieve the single name of this section, that is, the final part of the path returned by this method, you may use
getName().- Returns:
- Path of this section relative to its root
-
getName
String getName()Gets the name of this individualConfigurationSection, in the path.This will always be the final part of
getCurrentPath(), unless the section is orphaned.- Returns:
- Name of this section
-
getRoot
Configuration getRoot()Gets the rootConfigurationthat contains thisConfigurationSectionFor any
Configurationthemselves, this will return its own object.If the section is no longer contained within its root for any reason, such as being replaced with a different value, this may return null.
- Returns:
- Root configuration containing this section.
-
getParent
ConfigurationSection getParent()Gets the parentConfigurationSectionthat directly contains thisConfigurationSection.For any
Configurationthemselves, this will return null.If the section is no longer contained within its parent for any reason, such as being replaced with a different value, this may return null.
- Returns:
- Parent section containing this section.
-
get
Gets the requested Object by path.If the Object does not exist but a default value has been specified, this will return the default value. If the Object does not exist and no default value was specified, this will return null.
- Parameters:
path- Path of the Object to get.- Returns:
- Requested Object.
-
get
Gets the requested Object by path, returning a default value if not found.If the Object does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the Object to get.def- The default value to return if the path is not found.- Returns:
- Requested Object.
-
set
Sets the specified path to the given value.If value is null, the entry will be removed. Any existing entry will be replaced, regardless of what the new value is.
Some implementations may have limitations on what you may store. See their individual javadocs for details. No implementations should allow you to store
Configurations orConfigurationSections, please usecreateSection(String)for that.- Parameters:
path- Path of the object to set.value- New value to set the path to.
-
remove
Removes the specified path if it exists. The entry will be removed, either a value or an entire section.- Parameters:
path- Path of the object to remove.
-
createSection
Creates an emptyConfigurationSectionat the specified path.Any value that was previously set at this path will be overwritten. If the previous value was itself a
ConfigurationSection, it will be orphaned.- Parameters:
path- Path to create the section at.- Returns:
- Newly created section
-
createSection
Creates aConfigurationSectionat the specified path, with specified values.Any value that was previously set at this path will be overwritten. If the previous value was itself a
ConfigurationSection, it will be orphaned.- Parameters:
path- Path to create the section at.map- The values to used.- Returns:
- Newly created section
-
getString
Gets the requested String by path.If the String does not exist but a default value has been specified, this will return the default value. If the String does not exist and no default value was specified, this will return null.
- Parameters:
path- Path of the String to get.- Returns:
- Requested String.
-
getString
Gets the requested String by path, returning a default value if not found.If the String does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the String to get.def- The default value to return if the path is not found or is not a String.- Returns:
- Requested String.
-
isString
Checks if the specified path is a String.If the path exists but is not a String, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a String and return appropriately.
- Parameters:
path- Path of the String to check.- Returns:
- Whether or not the specified path is a String.
-
getInt
Gets the requested int by path.If the int does not exist but a default value has been specified, this will return the default value. If the int does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the int to get.- Returns:
- Requested int.
-
getInt
Gets the requested int by path, returning a default value if not found.If the int does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the int to get.def- The default value to return if the path is not found or is not an int.- Returns:
- Requested int.
-
isInt
Checks if the specified path is an int.If the path exists but is not a int, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a int and return appropriately.
- Parameters:
path- Path of the int to check.- Returns:
- Whether or not the specified path is an int.
-
getBoolean
Gets the requested boolean by path.If the boolean does not exist but a default value has been specified, this will return the default value. If the boolean does not exist and no default value was specified, this will return false.
- Parameters:
path- Path of the boolean to get.- Returns:
- Requested boolean.
-
getBoolean
Gets the requested boolean by path, returning a default value if not found.If the boolean does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the boolean to get.def- The default value to return if the path is not found or is not a boolean.- Returns:
- Requested boolean.
-
isBoolean
Checks if the specified path is a boolean.If the path exists but is not a boolean, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a boolean and return appropriately.
- Parameters:
path- Path of the boolean to check.- Returns:
- Whether or not the specified path is a boolean.
-
getByte
Gets the requested byte by path.If the byte does not exist but a default value has been specified, this will return the default value. If the byte does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the byte to get.- Returns:
- Requested byte.
-
getByte
Gets the requested byte by path, returning a default value if not found.If the byte does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the byte to get.def- The default value to return if the path is not found or is not a byte.- Returns:
- Requested byte.
-
isByte
Checks if the specified path is a byte.If the path exists but is not a byte, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a byte and return appropriately.
Note that values loaded from a YAML file are parsed as
Integer,LongorDouble, never asByte, so this will only return true for values set programmatically with a byte value, likeset(path, (byte) 1). To read a byte value from a file usegetByte(String), which converts any numeric value to a byte.- Parameters:
path- Path of the byte to check.- Returns:
- Whether or not the specified path is a byte.
-
getCharacter
Gets the requested char by path.If the char does not exist but a default value has been specified, this will return the default value. If the char does not exist and no default value was specified, this will return '\0'.
- Parameters:
path- Path of the char to get.- Returns:
- Requested char.
-
getCharacter
Gets the requested char by path, returning a default value if not found.If the char does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the char to get.def- The default value to return if the path is not found or is not a char.- Returns:
- Requested char.
-
isCharacter
Checks if the specified path is a char.If the path exists but is not a char, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a char and return appropriately.
Note that values loaded from a YAML file are parsed as
String, never asCharacter, so this will only return true for values set programmatically with a char value, likeset(path, 'a'). To read a char value from a file usegetCharacter(String), which converts single-character strings and numeric code points to a char.- Parameters:
path- Path of the char to check.- Returns:
- Whether or not the specified path is a char.
-
getDouble
Gets the requested double by path.If the double does not exist but a default value has been specified, this will return the default value. If the double does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the double to get.- Returns:
- Requested double.
-
getDouble
Gets the requested double by path, returning a default value if not found.If the double does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the double to get.def- The default value to return if the path is not found or is not a double.- Returns:
- Requested double.
-
isDouble
Checks if the specified path is a double.If the path exists but is not a double, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a double and return appropriately.
- Parameters:
path- Path of the double to check.- Returns:
- Whether or not the specified path is a double.
-
getFloat
Gets the requested float by path.If the float does not exist but a default value has been specified, this will return the default value. If the float does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the float to get.- Returns:
- Requested float.
-
getFloat
Gets the requested float by path, returning a default value if not found.If the float does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the float to get.def- The default value to return if the path is not found or is not a float.- Returns:
- Requested float.
-
isFloat
Checks if the specified path is a float.If the path exists but is not a float, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a float and return appropriately.
Note that values loaded from a YAML file are parsed as
Double, never asFloat, so this will only return true for values set programmatically with a float value, likeset(path, 1.5f). To read a float value from a file usegetFloat(String), which converts any numeric value to a float.- Parameters:
path- Path of the float to check.- Returns:
- Whether or not the specified path is a float.
-
getLong
Gets the requested long by path.If the long does not exist but a default value has been specified, this will return the default value. If the long does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the long to get.- Returns:
- Requested long.
-
getLong
Gets the requested long by path, returning a default value if not found.If the long does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the long to get.def- The default value to return if the path is not found or is not a long.- Returns:
- Requested long.
-
isLong
Checks if the specified path is a long.If the path exists but is not a long, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a long and return appropriately.
- Parameters:
path- Path of the long to check.- Returns:
- Whether or not the specified path is a long.
-
getShort
Gets the requested short by path.If the short does not exist but a default value has been specified, this will return the default value. If the short does not exist and no default value was specified, this will return 0.
- Parameters:
path- Path of the short to get.- Returns:
- Requested short.
-
getShort
Gets the requested short by path, returning a default value if not found.If the short does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the short to get.def- The default value to return if the path is not found or is not a short.- Returns:
- Requested short.
-
isShort
Checks if the specified path is a short.If the path exists but is not a short, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a short and return appropriately.
Note that values loaded from a YAML file are parsed as
Integer,LongorDouble, never asShort, so this will only return true for values set programmatically with a short value, likeset(path, (short) 1). To read a short value from a file usegetShort(String), which converts any numeric value to a short.- Parameters:
path- Path of the short to check.- Returns:
- Whether or not the specified path is a short.
-
getList
Gets the requested List by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return null.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List.
-
getList
Gets the requested List by path, returning a default value if not found.If the List does not exist then the specified default value will returned regardless of if a default has been identified in the root
Configuration.- Parameters:
path- Path of the List to get.def- The default value to return if the path is not found or is not a List.- Returns:
- Requested List.
-
isList
Checks if the specified path is a List.If the path exists but is not a List, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a List and return appropriately.
- Parameters:
path- Path of the List to check.- Returns:
- Whether or not the specified path is a List.
-
getStringList
Gets the requested List of String by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a String if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of String.
-
getIntegerList
Gets the requested List of Integer by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Integer if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Integer.
-
getBooleanList
Gets the requested List of Boolean by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Boolean if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Boolean.
-
getDoubleList
Gets the requested List of Double by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Double if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Double.
-
getFloatList
Gets the requested List of Float by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Float if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Float.
-
getLongList
Gets the requested List of Long by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Long if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Long.
-
getByteList
Gets the requested List of Byte by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Byte if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Byte.
-
getCharacterList
Gets the requested List of Character by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Character if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Character.
-
getShortList
Gets the requested List of Short by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Short if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Short.
-
getMapList
Gets the requested List of Maps by path.If the List does not exist but a default value has been specified, this will return the default value. If the List does not exist and no default value was specified, this will return an empty List.
This method will attempt to cast any values into a Map if possible, but may miss any values out if they are not compatible.
- Parameters:
path- Path of the List to get.- Returns:
- Requested List of Maps.
-
getConfigurationSection
Gets the requested ConfigurationSection by path.If the ConfigurationSection does not exist but a default value has been specified, this will return the default value. If the ConfigurationSection does not exist and no default value was specified, this will return null.
- Parameters:
path- Path of the ConfigurationSection to get.- Returns:
- Requested ConfigurationSection.
-
isConfigurationSection
Checks if the specified path is a ConfigurationSection.If the path exists but is not a ConfigurationSection, this will return false. If the path does not exist, this will return false. If the path does not exist but a default value has been specified, this will check if that default value is a ConfigurationSection and return appropriately.
- Parameters:
path- Path of the ConfigurationSection to check.- Returns:
- Whether or not the specified path is a ConfigurationSection.
-
getDefaultSection
ConfigurationSection getDefaultSection()Gets the equivalentConfigurationSectionfrom the defaultConfigurationdefined ingetRoot().If the root contains no defaults, or the defaults doesn't contain a value for this path, or the value at this path is not a
ConfigurationSectionthen this will return null.- Returns:
- Equivalent section in root configuration
-
addDefault
Sets the default value in the root at the given path as provided.If no source
Configurationwas provided as a default collection, then a newMemoryConfigurationwill be created to hold the new default value.If value is null, the value will be removed from the default Configuration source.
If the value as returned by
getDefaultSection()is null, then this will create a new section at the path, replacing anything that may have existed there previously.- Parameters:
path- Path of the value to set.value- Value to set the default to.- Throws:
IllegalArgumentException- Thrown if path is null.
-