Module watamebot

Class Plugin

java.lang.Object
net.foxgenesis.watame.plugin.Plugin

public abstract class Plugin extends Object
NEED_JAVADOC
Author:
Ashley
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final @NotNull Path
    Path to the plugin's configuration folder
    final @NotNull String
    Description of the plugin.
    final @NotNull String
    Friendly identifier of the plugin.
    protected final @NotNull org.slf4j.Logger
    Plugin logger
    final @NotNull String
    Name identifier of the plugin.
    final boolean
    Does this plugin require access to the database.
    final boolean
    Does this plugin provide commands.
    final @NotNull Runtime.Version
    Version of the plugin.
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-arg constructor to load and initialize required plugin data.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Called when the plugin is to be unloaded.
    boolean
    equals(@Nullable Object obj)
     
    protected @NotNull Collection<net.dv8tion.jda.api.interactions.commands.build.CommandData>
    Register all CommandData that this plugin provides.
    protected @Nullable org.apache.commons.configuration2.PropertiesConfiguration
    Get the configuration file that is linked to an identifier or null if not found.
     
    protected boolean
    Check if a configuration file with the specified identifier exists.
    int
     
    protected abstract void
    init(IEventStore builder)
    Startup method called when methods providing functionality are to be loaded.
    protected abstract void
    onConfigurationLoaded(String identifier, org.apache.commons.configuration2.Configuration properties)
    Startup method called during construction when a Configuration specified by a PluginConfiguration has been loaded.
    protected abstract void
    Startup method called during construction when the plugin.properties file has been loaded.
    protected abstract void
    Called by the PluginHandler when JDA and all Plugins have finished startup and have finished loading.
    protected abstract void
    Startup method called when JDA is building a connection to discord and all CommandData is being collected from getCommands().
    protected abstract void
    Startup method called when resources, needed for functionality initialization, are to be loaded.
    protected void
    Register custom databases.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • logger

      @NotNull protected final @NotNull org.slf4j.Logger logger
      Plugin logger
    • configurationPath

      @NotNull public final @NotNull Path configurationPath
      Path to the plugin's configuration folder
    • name

      @NotNull public final @NotNull String name
      Name identifier of the plugin.
    • friendlyName

      @NotNull public final @NotNull String friendlyName
      Friendly identifier of the plugin.
    • description

      @NotNull public final @NotNull String description
      Description of the plugin.
    • version

      @NotNull public final @NotNull Runtime.Version version
      Version of the plugin.
    • providesCommands

      public final boolean providesCommands
      Does this plugin provide commands.
    • needsDatabase

      public final boolean needsDatabase
      Does this plugin require access to the database.
  • Constructor Details

    • Plugin

      public Plugin() throws SeverePluginException
      No-arg constructor to load and initialize required plugin data.
      Throws:
      SeverePluginException - if the plugin is not in a named module or there was a problem while loading the plugin.properties file
  • Method Details

    • hasConfiguration

      protected boolean hasConfiguration(String identifier)
      Check if a configuration file with the specified identifier exists.
      Parameters:
      identifier - - the PluginConfiguration.identifier()
      Returns:
      Returns true if the specified identifier points to a valid configuration
    • getConfiguration

      @Nullable protected @Nullable org.apache.commons.configuration2.PropertiesConfiguration getConfiguration(String identifier)
      Get the configuration file that is linked to an identifier or null if not found.
      Parameters:
      identifier - - the PluginConfiguration.identifier()
      Returns:
      Returns the PropertiesConfiguration linked to the identifier
    • getCommands

      @NotNull protected @NotNull Collection<net.dv8tion.jda.api.interactions.commands.build.CommandData> getCommands()
      Register all CommandData that this plugin provides.

      ** providesCommands must be set to true in plugin.properties! **

      Returns:
      Returns a non-null Collection of CommandData that this Plugin provides
    • registerDatabases

      protected void registerDatabases(IDatabaseManager manager)
      Register custom databases.

      ** needsDatabase must be set to true in plugin.properties! **

      Parameters:
      manager - - database manager
    • onPropertiesLoaded

      protected abstract void onPropertiesLoaded(Properties properties)
      Startup method called during construction when the plugin.properties file has been loaded.

      DO NOT BLOCK IN THIS METHOD!

      Parameters:
      properties - - properties loaded from plugin.properties
      See Also:
    • onConfigurationLoaded

      protected abstract void onConfigurationLoaded(String identifier, org.apache.commons.configuration2.Configuration properties)
      Startup method called during construction when a Configuration specified by a PluginConfiguration has been loaded.

      DO NOT BLOCK IN THIS METHOD!

      Parameters:
      identifier - - the PluginConfiguration.identifier()
      properties - - the loaded Configuration
      See Also:
    • preInit

      protected abstract void preInit() throws SeverePluginException
      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.

      Database (guild settings) and Discord information might not be loaded at the time of this method! Use onReady(WatameBot) for functionality that requires valid connections.

      Typical resources to load here include:

      • Custom database registration
      • SQL compiled statements
      • 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

      protected abstract void init(IEventStore builder) throws SeverePluginException
      Startup method called when methods providing functionality are to be loaded. Methods that require connection to Discord or the database should be called here.

      Database (guild settings) and 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:

      • 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

      protected abstract void postInit(WatameBot bot) throws SeverePluginException
      Startup method called when JDA is building a connection to discord and all CommandData is being collected from getCommands().

      Database (guild settings) and Discord information might not be loaded at the time of this method! Use onReady(WatameBot) for functionality that requires valid connections.

      Parameters:
      bot - - reference of WatameBot
      Throws:
      SeverePluginException - Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded
    • onReady

      protected abstract void onReady(WatameBot bot) throws SeverePluginException
      Called by the PluginHandler when JDA and all Plugins have finished startup and have finished loading.
      Parameters:
      bot - - reference of WatameBot
      Throws:
      SeverePluginException - Thrown if the plugin has encountered a severe exception. If the exception is fatal, the plugin will be unloaded
      See Also:
    • close

      protected abstract void close() throws Exception
      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

      public String getDisplayInfo()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable @Nullable Object obj)
      Overrides:
      equals in class Object