Class BaseConfig
java.lang.Object
me.github.simonplays15.betterbansystem.api.files.BaseConfig
- Direct Known Subclasses:
LanguageFile
The `BaseConfig`
class is a configuration utility that provides methods to read and write configuration data using
YAML format.
It utilizes the `Yaml` library to parse and serialize the configuration data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.yaml.snakeyaml.Yaml
b()
Constructs a new instance of Yaml with the specified options.boolean
Checks if the specified path exists in the configuration.Retrieves the value associated with the specified key from the configuration.Retrieves the value associated with the specified key from the config map.boolean
getBoolean
(@NotNull String path) Retrieves the boolean value at the specified path in the configuration.boolean
getBoolean
(@NotNull String path, boolean def) Retrieves the boolean value associated with the specified path from the configuration.double
Retrieves a double value from the configuration using the given path.double
Returns the value associated with the given path as a double.int
Returns the integer value associated with the specified path in the configuration.int
Returns the integer value associated with the specified path in the configuration.@Nullable List<?>
Retrieves a list of objects from the configuration file at a given path.@Nullable List<?>
Retrieves a List value from the configuration based on the provided path.long
Returns the long value associated with the specified path.long
Retrieves a long value from the configuration at the specified path.@Nullable String
Retrieves the value of the specified path from the configuration as a string.@Nullable String
Retrieves a string value from the configuration.getStringList
(String path) Retrieves a list of strings from the specified path.getStringList
(String path, List<String> def) Returns a list of strings from the specified path in the configuration.boolean
Checks if the value at the specified path is a boolean.boolean
Check if the value located at the specified path is a double.boolean
Determines if the value stored at the specified path is of type Integer.boolean
Checks if the value at the specified path is a List.boolean
Checks if the value at the specified path is of type Long.boolean
Checks if the value at the specified path is a string.void
Loads the configuration from the given file.void
Saves the configuration to a file.
-
Constructor Details
-
BaseConfig
public BaseConfig()BaseConfig class is used for managing configurations.
-
-
Method Details
-
save
Saves the configuration to a file.- Parameters:
file
- the file to save the configuration to
-
load
Loads the configuration from the given file.- Parameters:
file
- The file to load the configuration from.
-
b
protected org.yaml.snakeyaml.Yaml b()Constructs a new instance of Yaml with the specified options.- Returns:
- a new instance of Yaml
-
get
Retrieves the value associated with the specified key from the configuration. If the value is not found, it returns the default value provided.- Parameters:
key
- The key to look up in the configuration (can be nested with dots)- Returns:
- The value associated with the key, or the default value if not found
-
get
Retrieves the value associated with the specified key from the config map. If the config map is empty, an empty string is returned. If the key is empty or null, null is returned. If the key does not contain a dot ('.'), the value associated with the key is returned from the config map, or the default value if the key is not found. If the key contains a dot ('.'), the value associated with the key is returned from the nested map structure, or null if any of the intermediate keys are missing or if the value is not found.- Parameters:
key
- the key to retrieve the value fordef
- the default value to return if the key is not found- Returns:
- the value associated with the key, or the default value if the key is not found
-
getString
Retrieves the value of the specified path from the configuration as a string.- Parameters:
path
- The path to the string value.- Returns:
- The string value associated with the specified path, or null if the path is not found.
-
getString
@Contract("_, !null -> !null") @Nullable public @Nullable String getString(@NotNull @NotNull String path, @Nullable @Nullable String def) Retrieves a string value from the configuration.- Parameters:
path
- the path of the string valuedef
- the default value to return if the path is not found- Returns:
- the string value at the specified path, or the default value if the path is not found
-
getInt
Returns the integer value associated with the specified path in the configuration. If no value is found, the default value provided is returned.- Parameters:
path
- The path to the integer value in the configuration. Cannot be null.- Returns:
- The integer value at the specified path, or the default value if no value is found.
-
getInt
Returns the integer value associated with the specified path in the configuration. If the value is not found or is not of type Number, the default value will be returned.- Parameters:
path
- the path to the value in the configurationdef
- the default value to be returned if the value is not found or is not of type Number- Returns:
- the integer value associated with the specified path, or the default value if not found or not of type Number
-
getBoolean
Retrieves the boolean value at the specified path in the configuration.- Parameters:
path
- the path to the boolean value in the configuration- Returns:
- the boolean value at the specified path, or false if it doesn't exist or is not a boolean
-
getBoolean
Retrieves the boolean value associated with the specified path from the configuration. If the path does not exist, or the value is not a boolean, the default value is returned.- Parameters:
path
- The path to the boolean value in the configuration.def
- The default value to return if the path does not exist or the value is not a boolean.- Returns:
- The boolean value associated with the specified path, or the default value if the path does not exist or the value is not a boolean.
-
getDouble
Retrieves a double value from the configuration using the given path.- Parameters:
path
- The path of the configuration value to retrieve.- Returns:
- The retrieved double value. If the value is not found or is not a number, the default value of 0.0 is returned.
-
getDouble
Returns the value associated with the given path as a double. If no value is found at the path, the default value is returned.- Parameters:
path
- the path to retrieve the value fromdef
- the default value to return if no value is found at the path- Returns:
- the value associated with the path as a double, or the default value if no value is found or the value is not a number
-
getLong
Returns the long value associated with the specified path.- Parameters:
path
- the path to the long value- Returns:
- the long value associated with the specified path, or 0L if the path does not exist
-
getLong
Retrieves a long value from the configuration at the specified path.- Parameters:
path
- the path to the configuration valuedef
- the default value to return if the configuration value is not found or is invalid- Returns:
- the long value at the specified path, or the default value if the configuration value is not found or is invalid
-
getList
Retrieves a list of objects from the configuration file at a given path.- Parameters:
path
- The path to the list in the configuration file.- Returns:
- The list of objects at the given path, or null if the path does not exist.
-
getList
@Contract("_, !null -> !null") @Nullable public @Nullable List<?> getList(@NotNull @NotNull String path, @Nullable @Nullable List<?> def) Retrieves a List value from the configuration based on the provided path.- Parameters:
path
- the path to the List value in the configuration (e.g., "parent.child.list")def
- the default List value to return if the path does not exist or the value is not a List- Returns:
- the List value associated with the path, or the default value if not found or not a List
-
getStringList
Retrieves a list of strings from the specified path.- Parameters:
path
- the path to the list- Returns:
- a list of strings from the specified path, an empty list if the path does not exist or is not a list
-
getStringList
Returns a list of strings from the specified path in the configuration.- Parameters:
path
- the path to the list of stringsdef
- the default list of strings to return if the specified path does not exist or is not a list of strings- Returns:
- a list of strings from the specified path, or the default list of strings if the specified path does not exist or is not a list of strings
-
contains
Checks if the specified path exists in the configuration.- Parameters:
path
- the path to check- Returns:
- true if the path exists, false otherwise
-
isString
Checks if the value at the specified path is a string.- Parameters:
path
- the path to the value- Returns:
- true if the value at the specified path is a string, false otherwise
-
isInt
Determines if the value stored at the specified path is of type Integer.- Parameters:
path
- the path of the value to check- Returns:
- true if the value is of type Integer, false otherwise
-
isBoolean
Checks if the value at the specified path is a boolean.- Parameters:
path
- the path to check- Returns:
- true if the value is a boolean, false otherwise
-
isDouble
Check if the value located at the specified path is a double.- Parameters:
path
- the path to the value- Returns:
- true if the value is a double, false otherwise
-
isLong
Checks if the value at the specified path is of type Long.- Parameters:
path
- the path to the value- Returns:
- true if the value is of type Long, false otherwise
-
isList
Checks if the value at the specified path is a List.- Parameters:
path
- The path to check.- Returns:
- True if the value at the specified path is a List, false otherwise.
-