java.lang.Object
me.github.simonplays15.betterbansystem.api.files.BaseConfig
Direct Known Subclasses:
LanguageFile

public class BaseConfig extends Object
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
    Constructor
    Description
    BaseConfig class is used for managing configurations.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.yaml.snakeyaml.Yaml
    b()
    Constructs a new instance of Yaml with the specified options.
    boolean
    contains (String path)
    Checks if the specified path exists in the configuration.
    get (String key)
    Retrieves the value associated with the specified key from the configuration.
    get (String key, Object def)
    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
    getDouble (@NotNull String path)
    Retrieves a double value from the configuration using the given path.
    double
    getDouble (@NotNull String path, double def)
    Returns the value associated with the given path as a double.
    int
    getInt (@NotNull String path)
    Returns the integer value associated with the specified path in the configuration.
    int
    getInt (@NotNull String path, int def)
    Returns the integer value associated with the specified path in the configuration.
    @Nullable List<?>
    getList (@NotNull String path)
    Retrieves a list of objects from the configuration file at a given path.
    @Nullable List<?>
    getList (@NotNull String path, @Nullable List<?> def)
    Retrieves a List value from the configuration based on the provided path.
    long
    getLong (@NotNull String path)
    Returns the long value associated with the specified path.
    long
    getLong (@NotNull String path, long def)
    Retrieves a long value from the configuration at the specified path.
    @Nullable String
    getString (@NotNull String path)
    Retrieves the value of the specified path from the configuration as a string.
    @Nullable String
    getString (@NotNull String path, @Nullable String def)
    Retrieves a string value from the configuration.
    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
    isBoolean (String path)
    Checks if the value at the specified path is a boolean.
    boolean
    isDouble (String path)
    Check if the value located at the specified path is a double.
    boolean
    isInt (String path)
    Determines if the value stored at the specified path is of type Integer.
    boolean
    isList (@NotNull String path)
    Checks if the value at the specified path is a List.
    boolean
    isLong (@NotNull String path)
    Checks if the value at the specified path is of type Long.
    boolean
    isString (String path)
    Checks if the value at the specified path is a string.
    void
    load (@NotNull File file)
    Loads the configuration from the given file.
    void
    save (File file)
    Saves the configuration to a file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BaseConfig

      public BaseConfig()
      BaseConfig class is used for managing configurations.
  • Method Details

    • save

      public void save (File file)
      Saves the configuration to a file.
      Parameters:
      file - the file to save the configuration to
    • load

      public void load (@NotNull @NotNull File file)
      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

      public Object get (String key)
      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

      public Object get (String key, Object def)
      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 for
      def - 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

      @Nullable public @Nullable String getString (@NotNull @NotNull String path)
      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 value
      def - 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

      public int getInt (@NotNull @NotNull String path)
      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

      public int getInt (@NotNull @NotNull String path, int def)
      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 configuration
      def - 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

      public boolean getBoolean (@NotNull @NotNull String path)
      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

      public boolean getBoolean (@NotNull @NotNull String path, boolean def)
      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

      public double getDouble (@NotNull @NotNull String path)
      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

      public double getDouble (@NotNull @NotNull String path, double def)
      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 from
      def - 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

      public long getLong (@NotNull @NotNull String path)
      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

      public long getLong (@NotNull @NotNull String path, long def)
      Retrieves a long value from the configuration at the specified path.
      Parameters:
      path - the path to the configuration value
      def - 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

      @Nullable public @Nullable List<?> getList (@NotNull @NotNull String path)
      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

      public List<String> getStringList (String path)
      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

      public List<String> getStringList (String path, List<String> def)
      Returns a list of strings from the specified path in the configuration.
      Parameters:
      path - the path to the list of strings
      def - 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

      public boolean contains (String path)
      Checks if the specified path exists in the configuration.
      Parameters:
      path - the path to check
      Returns:
      true if the path exists, false otherwise
    • isString

      public boolean isString (String path)
      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

      public boolean isInt (String path)
      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

      public boolean isBoolean (String path)
      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

      public boolean isDouble (String path)
      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

      public boolean isLong (@NotNull @NotNull String path)
      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

      public boolean isList (@NotNull @NotNull String path)
      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.