WatameBot.
Providers should provide a no-argument constructor or a
public static Plugin provider() method in accordance to
Provider.get()
- Author:
- Ashley
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull PathPath to the plugin's configuration folderfinal @NotNull StringDescription of the plugin.final @NotNull StringFriendly identifier of the plugin.protected final @NotNull org.slf4j.LoggerPlugin loggerfinal @NotNull StringName identifier of the plugin.final booleanDoes this plugin require access to the database.final booleanDoes this plugin provide commands.final @NotNull ModuleDescriptor.VersionVersion of the plugin. -
Constructor Summary
ConstructorsConstructorDescriptionPlugin()No-argument constructor called by theServiceLoaderto load and initialize required plugin data. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidclose()Called when the plugin is to be unloaded.Get a list of all loaded configurationIDs.booleanprotected voidforEachConfiguration(BiConsumer<String, org.apache.commons.configuration2.Configuration> consumer) Loop through all loadedConfigurationfiles.protected @Nullable org.apache.commons.configuration2.ConfigurationgetConfiguration(String identifier) Get the configuration file that is linked to anidentifierornullif not found.protected final PluginPropertygetProperty(String name) protected final PluginPropertygetProperty(PropertyInfo info) Resolve aPropertyInfointo a usablePluginProperty.protected final PluginPropertyProviderGet the provider for registering and gettingPluginProperties.protected booleanhasConfiguration(String identifier) Check if a configuration file with the specifiedidentifierexists.inthashCode()protected abstract voidinit(IEventStore builder) Startup method called when methods providing functionality are to be loaded.protected abstract voidCalled by thePluginHandlerwhenJDAand allPluginshave finished startup and have finished loading.protected abstract voidStartup method called whenJDAis building a connection to discord and allCommandDatais being collected fromCommandProvider.getCommands().protected abstract voidpreInit()Startup method called when resources, needed for functionality initialization, are to be loaded.protected final voidregisterDatabase(AbstractDatabase database) Register anAbstractDatabasethat thisPluginrequires.protected final PropertyInforegisterProperty(@NotNull String name, boolean modifiable, @NotNull PropertyType type) Register a plugin property inside the database.toString()protected final PluginPropertyupsertProperty(@NotNull String name, boolean modifiable, @NotNull PropertyType type) Register a plugin property if it doesn't exist and resolve it into aPluginProperty.
-
Field Details
-
logger
@NotNull protected final @NotNull org.slf4j.Logger loggerPlugin logger -
configurationPath
Path to the plugin's configuration folder -
name
Name identifier of the plugin. -
friendlyName
Friendly identifier of the plugin. -
description
Description of the plugin. -
version
Version of the plugin. -
providesCommands
public final boolean providesCommandsDoes this plugin provide commands. -
needsDatabase
public final boolean needsDatabaseDoes this plugin require access to the database.
-
-
Constructor Details
-
Plugin
No-argument constructor called by theServiceLoaderto load and initialize required plugin data.Types of plugin data would include:
- Configuration settings
- Constants
preInit()method.- Throws:
SeverePluginException- if the plugin is not in a named module or there was a problem while loading theplugin.propertiesfile
-
-
Method Details
-
configurationKeySet
Get a list of all loaded configurationIDs.- Returns:
- Returns a
Setcontaining theIDs of all configurations loaded
-
forEachConfiguration
protected void forEachConfiguration(BiConsumer<String, org.apache.commons.configuration2.Configuration> consumer) Loop through all loadedConfigurationfiles.- Parameters:
consumer- -PluginConfiguration.identifier()and the constructedConfiguration
-
hasConfiguration
Check if a configuration file with the specifiedidentifierexists.- Parameters:
identifier- - thePluginConfiguration.identifier()- Returns:
- Returns
trueif the specifiedidentifierpoints to a valid configuration
-
getConfiguration
@Nullable protected @Nullable org.apache.commons.configuration2.Configuration getConfiguration(String identifier) Get the configuration file that is linked to anidentifierornullif not found.- Parameters:
identifier- - thePluginConfiguration.identifier()- Returns:
- Returns the
PropertiesConfigurationlinked to theidentifier
-
registerProperty
protected final PropertyInfo registerProperty(@NotNull @NotNull String name, boolean modifiable, @NotNull @NotNull PropertyType type) Register a plugin property inside the database.- Parameters:
name- - name of the propertymodifiable- - if this property can be modified by a usertype- - property storage type- Returns:
- Returns the
PropertyInfoof the registered property
-
upsertProperty
protected final PluginProperty upsertProperty(@NotNull @NotNull String name, boolean modifiable, @NotNull @NotNull PropertyType type) Register a plugin property if it doesn't exist and resolve it into aPluginProperty.- Parameters:
name- - property namemodifiable- - if this property can be modified by a usertype- - property storage type- Returns:
- Returns the resolved
PluginProperty
-
getProperty
Resolve aPropertyInfointo a usablePluginProperty.- Parameters:
info- - property information- Returns:
- Returns the resolved
PluginProperty
-
getProperty
- Parameters:
name- - property name- Returns:
- Returns the resolved
PluginProperty
-
getPropertyProvider
Get the provider for registering and gettingPluginProperties.- Returns:
- Returns the
PluginPropertyProviderused byPluginsto register plugin properties
-
registerDatabase
Register anAbstractDatabasethat thisPluginrequires.- Parameters:
database- - database to register- Throws:
IOException- Thrown if there was an error while reading the database setup files
-
preInit
Startup method called when resources, needed for functionality initialization, are to be loaded. Resources that do not require connection to Discord or the database should be loaded here.The database and Discord information might not be loaded at the time of this method! Use
init(IEventStore)for functionality that requires valid connections.Typical resources to load here include:
- Custom database registration
- System Data
- Files
- Images
- Throws:
SeverePluginException- Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded- See Also:
-
init
Startup method called when methods providing functionality are to be loaded. Methods that require connection the database should be called here.Discord information might not be loaded at the time of this method! Use
onReady(WatameBot)for functionality that requires valid connections.Typical methods to call here include:
- Main chunk of program initialization
PluginPropertyregistration/retrieval- Event listener registration
- Custom database operations
- Parameters:
builder- - discord event listener register- Throws:
SeverePluginException- Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded- See Also:
-
postInit
Startup method called whenJDAis building a connection to discord and allCommandDatais being collected fromCommandProvider.getCommands().Discord information might not be loaded at the time of this method! Use
onReady(WatameBot)for functionality that requires valid connections.Typical methods to call here include:
- Initialization cleanup
- Parameters:
bot- - reference ofWatameBot- Throws:
SeverePluginException- Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded
-
onReady
Called by thePluginHandlerwhenJDAand allPluginshave finished startup and have finished loading.- Parameters:
bot- - reference ofWatameBot- Throws:
SeverePluginException- Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded- See Also:
-
close
Called when the plugin is to be unloaded.The shutdown sequence runs as followed:
- Remove event listeners
close()- Close databases
- Throws:
Exception- Thrown if an underlying exception is thrown during close
-
getDisplayInfo
-
toString
-
hashCode
public int hashCode() -
equals
-