Class Plugin

  • Direct Known Subclasses:
    FocessQQ.MainPlugin, LazyPlugin

    public abstract class Plugin
    extends Object
    Represent a Plugin class that can be load, enable and disable. Also, provide plenty of API for the plugin to get better with this framework. You should declare PluginType to this class.
    • Constructor Detail

      • Plugin

        public Plugin​(String name,
                      String author,
                      top.focess.util.version.Version version)
        Initialize a Plugin instance by its name. Never instance it! It will be instanced when bot bootstraps automatically.
        Parameters:
        name - the plugin name
        author - the plugin author
        version - the plugin version
        Throws:
        PluginLoaderException - if the classloader of the plugin is not PluginClassLoader
        PluginDuplicateException - if the plugin is already loaded
        IllegalStateException - if the plugin is newed in runtime
      • Plugin

        protected Plugin()
        Provide a constructor to help PluginType design. Never instance it! It will be instanced when bot bootstraps automatically.
    • Method Detail

      • getPlugins

        @NotNull
        public static List<Plugin> getPlugins()
        Get all the loaded plugins
        Returns:
        all the loaded plugins
      • getPlugin

        public static @Nullable Plugin getPlugin​(Class<? extends Plugin> plugin)
        Get Plugin instance by the class instance
        Parameters:
        plugin - the class instance of the plugin
        Returns:
        the plugin instance
      • getPlugin

        public static @Nullable Plugin getPlugin​(String name)
        Get Plugin instance by the name
        Parameters:
        name - the name of the plugin
        Returns:
        the plugin instance
      • thisPlugin

        public static @Nullable Plugin thisPlugin()
        Get the plugin by its caller class
        Returns:
        the plugin or null if not found
      • plugin

        public static @NonNull Plugin plugin()
        Get the plugin by its caller class Note: this method will not return null. If the thisPlugin() is null, it will return FocessQQ.getMainPlugin()
        Returns:
        the plugin
      • getName

        public final @NonNull String getName()
      • enable

        public abstract void enable()
        Used to initialize the plugin
      • disable

        public abstract void disable()
        Used to save some data of the plugin
      • onEnable

        public final void onEnable()
      • onDisable

        public final void onDisable()
      • getDefaultFolder

        public final @NonNull File getDefaultFolder()
      • equals

        public boolean equals​(@Nullable Object o)
        Overrides:
        equals in class Object
      • hashCode

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

        public final void registerListener​(Listener listener)
        Register the listener into the Event chain
        Parameters:
        listener - the listener need to be registered
      • getAuthor

        public final String getAuthor()
      • getVersion

        public final top.focess.util.version.Version getVersion()
      • getLangConfig

        public final LangConfig getLangConfig()
      • getDefaultConfig

        public final DefaultConfig getDefaultConfig()
      • loadResource

        public final @Nullable InputStream loadResource​(String path)
        Get the resource of the plugin
        Parameters:
        path - the path of the resource
        Returns:
        the resource or null if not found
      • isEnabled

        public final boolean isEnabled()
      • unload

        public final void unload()
        Used to unload this plugin during enabling process This should be called in the enable() method
        Throws:
        PluginUnloadException - to indicate that the plugin should be unloaded