Package wbs.utils.util.configuration
Class WbsConfigReader
java.lang.Object
wbs.utils.util.configuration.WbsConfigReader
A static class to read configs and automatically provide errors to the WbsSettings object without external logic
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Enum<T>>
TgetEnum(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz) Get a list ofWbsConfigReaderfrom a String listgetEnumList(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz) Get a list ofWbsConfigReaderfrom a String liststatic <T extends Enum<T>>
TgetRequiredEnum(@NotNull org.bukkit.configuration.ConfigurationSection section, String field, @Nullable WbsSettings settings, @Nullable String directory, Class<T> clazz) Get a list ofWbsConfigReaderfrom a String liststatic @NotNull org.bukkit.LocationgetRequiredLocation(@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.ConfigurationSectiongetRequiredSection(@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 booleanisNull(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 settingsstatic booleanisNull(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 settingsstatic voidrequireNotNull(@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 settingsstatic voidrequireSection(@NotNull org.bukkit.configuration.ConfigurationSection section, String sectionName, @Nullable WbsSettings settings, @Nullable String directory)
-
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 keyfield- The keysettings- The settings to log errors todirectory- 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 keyfield- The keysettings- The settings to log errors todirectory- 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 checksectionName- The name of the field to verify exists, and is a sectionsettings- The settings to log to if the target section is missingdirectory- 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 sectionsectionName- The name of the section to retrievesettings- The settings to log to if the target section is missingdirectory- 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 ofWbsConfigReaderfrom a String list- Parameters:
section- The section to read fromfield- The name of the field that contains a String to parse asWbsConfigReadersettings- The settings to log to if a value is invalid for the given enum classdirectory- The path to the field for if settings is definedclazz- 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 ofWbsConfigReaderfrom a String list- Parameters:
section- The section to read fromfield- The name of the field that contains a String to parse asWbsConfigReadersettings- The settings to log to if a value is invalid for the given enum classdirectory- The path to the field for if settings is definedclazz- 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 ofWbsConfigReaderfrom a String list- Parameters:
section- The section to read fromfield- The name of the field that contains the String listsettings- The settings to log to if a value is invalid for the given enum classdirectory- The path to the field for if settings is definedclazz- 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 keyfield- The keysettings- The settings to log errors todirectory- The path to the object being configurederror- 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 fromsectionName- The name of the subsection to read from within sectionsettings- The settings to log errors to automatically, if provideddirectory- 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 missingInvalidWorldException- If the world field was set, but is not a valid/loaded world.
-