Class WbsConfigReader

java.lang.Object
wbs.utils.util.configuration.WbsConfigReader

public final class WbsConfigReader extends Object
A static class to read configs and automatically provide errors to the WbsSettings object without external logic
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends Enum<T>>
    T
    getEnum(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz)
    Get a list of WbsConfigReader from a String list
    static <T extends Enum<T>>
    @NotNull List<T>
    getEnumList(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz)
    Get a list of WbsConfigReader from a String list
    static <T extends Enum<T>>
    T
    getRequiredEnum(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz)
    Get a list of WbsConfigReader from a String list
    static @NotNull org.bukkit.Location
    getRequiredLocation(@NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable WbsSettings settings, @Nullable String directory)
    Get a non-null location given the name of a config section, and automatically log errors to the provided settings if non-null.
    static @NotNull org.bukkit.configuration.ConfigurationSection
    getRequiredSection(@NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable WbsSettings settings, @Nullable String directory)
    Get a required section from a ConfigurationSection, and throw an error if missing.
    static boolean
    isNull(org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory)
    Check if a config is null, and if it is, log it against the current settings
    static boolean
    isNull(org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, @Nullable String error)
    Check if a config is null, and if it is, log it against the current settings
    static void
    requireNotNull(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory)
    Check if a config is null, and if it is, log it against the current settings
    static void
    requireSection(@NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable WbsSettings settings, @Nullable String directory)
     

    Methods inherited from class java.lang.Object

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

    • isNull

      public static boolean isNull(org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory)
      Check if a config is null, and if it is, log it against the current settings
      Parameters:
      section - The section to check for a key
      field - The key
      settings - The settings to log errors to
      directory - The path to the object being configured
      Returns:
      True if the field is missing
    • requireNotNull

      public static void requireNotNull(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory) throws MissingRequiredKeyException
      Check if a config is null, and if it is, log it against the current settings
      Parameters:
      section - The section to check for a key
      field - The key
      settings - The settings to log errors to
      directory - The path to the object being configured
      Throws:
      MissingRequiredKeyException
    • requireSection

      public static void requireSection(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory) throws MissingRequiredKeyException
      Parameters:
      section - The parent section to check
      sectionName - The name of the field to verify exists, and is a section
      settings - The settings to log to if the target section is missing
      directory - The path to the section if settings is defined
      Throws:
      MissingRequiredKeyException - If the field does not exist, or is not a section
    • getRequiredSection

      @NotNull public static @NotNull org.bukkit.configuration.ConfigurationSection getRequiredSection(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory) throws MissingRequiredKeyException
      Get a required section from a ConfigurationSection, and throw an error if missing.
      Parameters:
      section - The parent section
      sectionName - The name of the section to retrieve
      settings - The settings to log to if the target section is missing
      directory - The path to the section if settings is defined
      Returns:
      The found section, guaranteed not to be null
      Throws:
      MissingRequiredKeyException
    • getRequiredEnum

      @NotNull public static <T extends Enum<T>> T getRequiredEnum(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory, Class<T> clazz) throws InvalidConfigurationException
      Get a list of WbsConfigReader from a String list
      Parameters:
      section - The section to read from
      field - The name of the field that contains a String to parse as WbsConfigReader
      settings - The settings to log to if a value is invalid for the given enum class
      directory - The path to the field for if settings is defined
      clazz - The enum class to build from the given String
      Returns:
      A non-null enum value
      Throws:
      InvalidConfigurationException
    • getEnum

      @Nullable public static <T extends Enum<T>> T getEnum(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory, Class<T> clazz) throws InvalidConfigurationException
      Get a list of WbsConfigReader from a String list
      Parameters:
      section - The section to read from
      field - The name of the field that contains a String to parse as WbsConfigReader
      settings - The settings to log to if a value is invalid for the given enum class
      directory - The path to the field for if settings is defined
      clazz - The enum class to build from the given String
      Returns:
      An enum that may be null
      Throws:
      InvalidConfigurationException
    • getEnumList

      @NotNull public static <T extends Enum<T>> @NotNull List<T> getEnumList(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory, Class<T> clazz)
      Get a list of WbsConfigReader from a String list
      Parameters:
      section - The section to read from
      field - The name of the field that contains the String list
      settings - The settings to log to if a value is invalid for the given enum class
      directory - The path to the field for if settings is defined
      clazz - The enum class to build from the given String list
      Returns:
      A list of enum values that may be empty
    • isNull

      public static boolean isNull(org.bukkit.configuration.ConfigurationSection section, String field, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory, @Nullable @Nullable String error)
      Check if a config is null, and if it is, log it against the current settings
      Parameters:
      section - The section to check for a key
      field - The key
      settings - The settings to log errors to
      directory - The path to the object being configured
      error - The error to show if the object does not exist
      Returns:
      True if the field is missing
    • getRequiredLocation

      @NotNull public static @NotNull org.bukkit.Location getRequiredLocation(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable @Nullable WbsSettings settings, @Nullable @Nullable String directory) throws MissingRequiredKeyException, InvalidWorldException
      Get a non-null location given the name of a config section, and automatically log errors to the provided settings if non-null.
      Parameters:
      section - The section to read from
      sectionName - The name of the subsection to read from within section
      settings - The settings to log errors to automatically, if provided
      directory - The path taken to the section to read from, for logging purposes only
      Returns:
      The non-null location found.
      Throws:
      MissingRequiredKeyException - If a field (sectionName, x, y, z, or world) is missing
      InvalidWorldException - If the world field was set, but is not a valid/loaded world.