Package wbs.utils.util.plugin
Class WbsSettings
java.lang.Object
wbs.utils.util.plugin.WbsSettings
Contains all configuration settings that aren't universal to WbsPlugin
and provides methods to access them.
Includes methods for logging configuration errors and safely loading configs.
- Author:
- Weber588
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FileRetrieve a file from the plugin data folder.protected org.bukkit.configuration.file.YamlConfigurationloadConfigSafely(File file) A version ofYamlConfiguration.loadConfiguration(File)that also logs yaml parsing errors.protected org.bukkit.configuration.file.YamlConfigurationloadDefaultConfig(String configName) protected voidloadMessageFormat(org.bukkit.configuration.file.YamlConfiguration config) voidLog an error both in console and in the errors list that may be used to display errors in a commandabstract voidreload()To be called during initialization, and allows the configs to be reloaded without restarting the server/reloading the whole plugin.protected org.bukkit.configuration.file.YamlConfigurationsaveYamlData(@Nullable org.bukkit.configuration.file.YamlConfiguration config, @NotNull String fileName, @NotNull String dataName, @NotNull Consumer<org.bukkit.configuration.file.YamlConfiguration> delegate) Runs an operation on a YamlConfiguration as defined in the delegate after guaranteeing that the config is non-null and corresponding file exists in the given plugins folder.
-
Field Details
-
plugin
-
logger
-
errors
-
-
Constructor Details
-
WbsSettings
-
-
Method Details
-
reload
public abstract void reload()To be called during initialization, and allows the configs to be reloaded without restarting the server/reloading the whole plugin. -
loadDefaultConfig
-
loadMessageFormat
protected void loadMessageFormat(org.bukkit.configuration.file.YamlConfiguration config) -
getErrors
- Returns:
- The errors from the last reload/initial load
-
logError
Log an error both in console and in the errors list that may be used to display errors in a command- Parameters:
error- The error messagedirectory- The directory in which the error took place
-
loadConfigSafely
A version ofYamlConfiguration.loadConfiguration(File)that also logs yaml parsing errors.- Parameters:
file- The file to parse- Returns:
- The YamlConfiguration
-
genConfig
Retrieve a file from the plugin data folder. If it does not exist, it will be created from the jar- Parameters:
path- The path of the file within the plugins data folder- Returns:
- The new file, or the file that was present at the path.
-
saveYamlData
protected org.bukkit.configuration.file.YamlConfiguration saveYamlData(@Nullable @Nullable org.bukkit.configuration.file.YamlConfiguration config, @NotNull @NotNull String fileName, @NotNull @NotNull String dataName, @NotNull @NotNull Consumer<org.bukkit.configuration.file.YamlConfiguration> delegate) Runs an operation on a YamlConfiguration as defined in the delegate after guaranteeing that the config is non-null and corresponding file exists in the given plugins folder. Automatically logs errors, formatted with the given dataName.- Parameters:
config- Optionally, the configuration to write to and save. Leave as null to automatically load from the givenfileName- The file to save to and read from if config is nulldataName- The name of the thing being saved. For example, using "Player" will make the file created message say "Player file created."delegate- The function to run on the YamlConfiguration before saving- Returns:
- The used YamlConfiguration; this is config if non-null.
-