Class ConfigurationFile

java.lang.Object
preponderous.ponder.misc.ConfigurationFile

public class ConfigurationFile extends Object
The ConfigurationFile class stands for one Configuration File.

The default operation of this class is a bridge between BukkitAPI and this API.
The default values of this class are 'config.yml' and 'load from jar'.

Since:
14/06/2021 - 09:34
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    Constant which can be used throughout the creation of a Configuration File.
    static boolean
    Constant which can be used throughout the creation of a Configuration File.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor to generate the default ConfigurationFile.
    ConfigurationFile​(@NotNull String name, boolean preloadedResource)
    Constructor to generate a ConfigurationFile.
    ConfigurationFile​(@NotNull String name, boolean preloadedResource, org.bukkit.plugin.java.JavaPlugin plugin)
    Constructor to generate a ConfigurationFile and initialize it with a java plugin.
    ConfigurationFile​(@NotNull String name, @NotNull String extension, boolean preloadedResource)
    Constructor to generate a ConfigurationFile.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Object
    get​(@NotNull String path)
    Method to get something at the specified path.
    boolean
    getBoolean​(@NotNull String path)
    Method to obtain a boolean at the given path.
    @NotNull List<Boolean>
    getBooleanList​(@NotNull String path)
    Method to obtain a boolean-list at the given path.
    boolean
    getBooleanOrDefault​(@NotNull String path, boolean defaultValue)
    Method to obtain a boolean at the given path or a default value if not found.
    double
    getDouble​(@NotNull String path)
    Method to obtain a double at the given path.
    @NotNull List<Double>
    getDoubleList​(@NotNull String path)
    Method to obtain a double-list at the given path.
    double
    getDoubleOrDefault​(@NotNull String path, double defaultValue)
    Method to obtain a double at the given path or a default value if not found.
    float
    getFloat​(@NotNull String path)
    Method to obtain a float at the given path.
    @NotNull List<Float>
    getFloatList​(@NotNull String path)
    Method to obtain a float-list at the given path.
    float
    getFloatOrDefault​(@NotNull String path, float defaultValue)
    Method to obtain a float at the given path or a default value if not found.
    int
    getInt​(@NotNull String path)
    Method to obtain an integer at the given path.
    @NotNull List<Integer>
    getIntList​(@NotNull String path)
    Method to obtain a int-list at the given path.
    int
    getIntOrDefault​(@NotNull String path, int defaultValue)
    Method to obtain an integer at the given path or a default value if not found.
    @NotNull List<?>
    getList​(@NotNull String path)
    Method to obtain a list at the given path.
    long
    getLong​(@NotNull String path)
    Method to obtain a long at the given path.
    @NotNull List<Long>
    getLongList​(@NotNull String path)
    Method to obtain a long-list at the given path.
    long
    getLongOrDefault​(@NotNull String path, long defaultValue)
    Method to obtain a long at the given path or a default value if not found.
    @NotNull Object
    getOrDefault​(@NotNull String path, @NotNull Object defaultValue)
    Method to get something at the specified path.
    org.bukkit.plugin.java.JavaPlugin
    Method to get the plugin associated with the configuration file.
    @Nullable org.bukkit.configuration.ConfigurationSection
    getSection​(@NotNull String path)
    Method to obtain a ConfigurationSection from path.
    @NotNull String
    getString​(@NotNull String path)
    Method to obtain a String from the Configuration using Yaml Methods.
    @NotNull List<String>
    getStringList​(@NotNull String path)
    Method to obtain a string-list at the given path.
    @NotNull String
    getStringOrDefault​(@NotNull String path, @NotNull String defaultValue)
    Method to obtain a String or return a Default Value if not found.
    boolean
    hasSection​(@NotNull String path)
    Method to determine if the Configuration File has the specified ConfigurationSection.
    void
    initializePlugin​(org.bukkit.plugin.java.JavaPlugin plugin)
    Method to initialize the plugin for the configuration file.
    void
    Method to save the Configuration File.
    void
    set​(@NotNull String path, @Nullable Object value)
    Method to set the value at a given path.
    void
    set​(@NotNull String path, @Nullable Object value, boolean save)
    Method to set the value at a given path and optionally save it, when done.

    Methods inherited from class java.lang.Object

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

    • LOAD_FROM_JAR

      public static final boolean LOAD_FROM_JAR
      Constant which can be used throughout the creation of a Configuration File.
      See Also:
      Constant Field Values
    • CREATE_EMPTY_FILE

      public static final boolean CREATE_EMPTY_FILE
      Constant which can be used throughout the creation of a Configuration File.
      See Also:
      Constant Field Values
  • Constructor Details

    • ConfigurationFile

      public ConfigurationFile()
      Constructor to generate the default ConfigurationFile.

      The default name is 'config.yml' and it loads it from the Jar.

    • ConfigurationFile

      public ConfigurationFile(@NotNull @NotNull String name, boolean preloadedResource, org.bukkit.plugin.java.JavaPlugin plugin)
      Constructor to generate a ConfigurationFile and initialize it with a java plugin.
      Parameters:
      name - of the file.
      preloadedResource - or not. true if the Jar contains a default version of this file.
      plugin - JavaPlugin used to initialize the configuration file.
      Since:
      10/27/2021
    • ConfigurationFile

      public ConfigurationFile(@NotNull @NotNull String name, boolean preloadedResource)
      Constructor to generate a ConfigurationFile.
      Parameters:
      name - of the file.
      preloadedResource - or not. true if the Jar contains a default version of this file.
    • ConfigurationFile

      public ConfigurationFile(@NotNull @NotNull String name, @NotNull @NotNull String extension, boolean preloadedResource)
      Constructor to generate a ConfigurationFile.
      Parameters:
      name - of the file.
      extension - of the file.
      preloadedResource - or not. true if the Jar contains a default version of this file.
  • Method Details

    • saveConfig

      public void saveConfig()
      Method to save the Configuration File.
      See Also:
      FileConfiguration.save(File)
    • getSection

      @Nullable public @Nullable org.bukkit.configuration.ConfigurationSection getSection(@NotNull @NotNull String path)
      Method to obtain a ConfigurationSection from path.
      Parameters:
      path - to obtain the section from.
      Returns:
      ConfigurationSection or null (If not found).
      See Also:
      hasSection(String)
    • hasSection

      public boolean hasSection(@NotNull @NotNull String path)
      Method to determine if the Configuration File has the specified ConfigurationSection.
      Parameters:
      path - to determine existence.
      Returns:
      true if it does.
    • get

      @NotNull public @NotNull Object get(@NotNull @NotNull String path)
      Method to get something at the specified path.
      Parameters:
      path - of the data.
      Returns:
      Object never, null.
    • getOrDefault

      @NotNull public @NotNull Object getOrDefault(@NotNull @NotNull String path, @NotNull @NotNull Object defaultValue)
      Method to get something at the specified path.
      Parameters:
      path - of the data.
      defaultValue - to send back if there is no data found.
      Returns:
      Object never, null.
    • getString

      @NotNull public @NotNull String getString(@NotNull @NotNull String path)
      Method to obtain a String from the Configuration using Yaml Methods.

      If the String isn't found at the path specified, it defaults to 'path is missing' to help with development.

      Parameters:
      path - to obtain the value at.
      Returns:
      String regardless of existence.
      See Also:
      getStringOrDefault(String, String)
    • getStringOrDefault

      @NotNull public @NotNull String getStringOrDefault(@NotNull @NotNull String path, @NotNull @NotNull String defaultValue)
      Method to obtain a String or return a Default Value if not found.
      Parameters:
      path - to obtain the value at.
      defaultValue - if the value isn't found.
      Returns:
      String regardless of existence.
    • getInt

      public int getInt(@NotNull @NotNull String path)
      Method to obtain an integer at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      Integer or 0
    • getIntOrDefault

      public int getIntOrDefault(@NotNull @NotNull String path, int defaultValue)
      Method to obtain an integer at the given path or a default value if not found.
      Parameters:
      path - to get the value at.
      defaultValue - to return if not found.
      Returns:
      Integer or the defaultValue.
    • getDouble

      public double getDouble(@NotNull @NotNull String path)
      Method to obtain a double at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      Double or 0.0D
    • getDoubleOrDefault

      public double getDoubleOrDefault(@NotNull @NotNull String path, double defaultValue)
      Method to obtain a double at the given path or a default value if not found.
      Parameters:
      path - to get the value at.
      defaultValue - to return if not found.
      Returns:
      Double or the defaultValue.
    • getFloat

      public float getFloat(@NotNull @NotNull String path)
      Method to obtain a float at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      Float or 0.0F
    • getFloatOrDefault

      public float getFloatOrDefault(@NotNull @NotNull String path, float defaultValue)
      Method to obtain a float at the given path or a default value if not found.
      Parameters:
      path - to get the value at.
      defaultValue - to return if not found.
      Returns:
      Float or the defaultValue.
    • getLong

      public long getLong(@NotNull @NotNull String path)
      Method to obtain a long at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      Long or 0L
    • getLongOrDefault

      public long getLongOrDefault(@NotNull @NotNull String path, long defaultValue)
      Method to obtain a long at the given path or a default value if not found.
      Parameters:
      path - to get the value at.
      defaultValue - to return if not found.
      Returns:
      Long or the defaultValue.
    • getBoolean

      public boolean getBoolean(@NotNull @NotNull String path)
      Method to obtain a boolean at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      Boolean or false
    • getBooleanOrDefault

      public boolean getBooleanOrDefault(@NotNull @NotNull String path, boolean defaultValue)
      Method to obtain a boolean at the given path or a default value if not found.
      Parameters:
      path - to get the value at.
      defaultValue - to return if not found.
      Returns:
      Boolean or the defaultValue.
    • getList

      @NotNull public @NotNull List<?> getList(@NotNull @NotNull String path)
      Method to obtain a list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List
    • getStringList

      @NotNull public @NotNull List<String> getStringList(@NotNull @NotNull String path)
      Method to obtain a string-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of String
    • getIntList

      @NotNull public @NotNull List<Integer> getIntList(@NotNull @NotNull String path)
      Method to obtain a int-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of Integer
    • getLongList

      @NotNull public @NotNull List<Long> getLongList(@NotNull @NotNull String path)
      Method to obtain a long-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of Long
    • getDoubleList

      @NotNull public @NotNull List<Double> getDoubleList(@NotNull @NotNull String path)
      Method to obtain a double-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of Double
    • getFloatList

      @NotNull public @NotNull List<Float> getFloatList(@NotNull @NotNull String path)
      Method to obtain a float-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of Float
    • getBooleanList

      @NotNull public @NotNull List<Boolean> getBooleanList(@NotNull @NotNull String path)
      Method to obtain a boolean-list at the given path.
      Parameters:
      path - to get the value at.
      Returns:
      List of Boolean
    • set

      public void set(@NotNull @NotNull String path, @Nullable @Nullable Object value)
      Method to set the value at a given path.

      This method calls set(String, Object, boolean) with a default of false.

      Parameters:
      path - to set as value.
      value - to set at the location of the path.
      See Also:
      set(String, Object, boolean)
    • set

      public void set(@NotNull @NotNull String path, @Nullable @Nullable Object value, boolean save)
      Method to set the value at a given path and optionally save it, when done.
      Parameters:
      path - to set as value.
      value - to set at the location of the path.
      save - to determine if the plugin should save after the value has been set.
      See Also:
      saveConfig()
    • initializePlugin

      public void initializePlugin(org.bukkit.plugin.java.JavaPlugin plugin)
      Method to initialize the plugin for the configuration file.
      Since:
      10/27/2021
    • getPlugin

      public org.bukkit.plugin.java.JavaPlugin getPlugin()
      Method to get the plugin associated with the configuration file.
      Since:
      10/27/2021