Package top.focess.qq.api.plugin
Class Plugin
- java.lang.Object
-
- top.focess.qq.api.plugin.Plugin
-
- All Implemented Interfaces:
Serializable,top.focess.util.serialize.FocessSerializable
- Direct Known Subclasses:
FocessQQ.MainPlugin,LazyPlugin
public abstract class Plugin extends Object implements top.focess.util.serialize.FocessSerializable
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 declarePluginTypeto this class.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Plugin()Initialize a Plugin Instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static @Nullable Plugindeserialize(Map<String,Object> map)abstract voiddisable()Used to save some data of the pluginabstract voidenable()Used to initialize the pluginbooleanequals(@Nullable Object o)StringgetAuthor()DefaultConfiggetDefaultConfig()@NonNull FilegetDefaultFolder()@Nullable FilegetFile()Get the plugin jar fileLangConfiggetLangConfig()@NonNull StringgetName()static @Nullable PlugingetPlugin(Class<? extends Plugin> plugin)Get Plugin instance by the class instancestatic @Nullable PlugingetPlugin(String name)Get Plugin instance by the namePluginDescriptiongetPluginDescription()static @NotNull @UnmodifiableView List<Plugin>getPlugins()Get all the loaded pluginstop.focess.util.version.VersiongetVersion()inthashCode()voidinitialize()booleanisEnabled()booleanisInitialized()Indicate whether the plugin is initialized or not@Nullable InputStreamloadResource(String path)Get the resource of the pluginvoidonDisable()voidonEnable()static @NonNull Pluginplugin()Get the plugin by its caller class Note: this method will not return null.voidregisterBuffer(top.focess.command.DataConverter<?> dataConverter, top.focess.command.DataCollection.BufferGetter bufferGetter)Register the getter of the buffervoidregisterCommand(Command command)Register the commandvoidregisterListener(Listener listener)Register the listener into the Event chainvoidregisterSpecialArgumentComplexHandler(String name, SpecialArgumentComplexHandler handler)Register the special argument handler@Nullable Map<String,Object>serialize()static @Nullable PluginthisPlugin()Get the plugin by its caller classvoidunload()Used to unload this plugin during enabling process This should be called in theenable()method
-
-
-
Constructor Detail
-
Plugin
public Plugin()
Initialize a Plugin Instance. Never instance it! It will be instanced when bot bootstraps automatically.- Throws:
PluginLoaderException- if the classloader of the plugin is notPluginClassLoaderPluginDuplicateException- if the plugin is already loadedIllegalStateException- if the plugin is newed in runtimeIllegalArgumentException- if the plugin name is empty
-
-
Method Detail
-
getPlugins
@NotNull public static @NotNull @UnmodifiableView 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 thethisPlugin()is null, it will returnFocessQQ.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()
-
registerListener
public final void registerListener(Listener listener)
Register the listener into the Event chain- Parameters:
listener- the listener need to be registered
-
registerCommand
public final void registerCommand(Command command)
Register the command- Parameters:
command- the command need to be registered- See Also:
Command.register(Plugin, Command)
-
registerBuffer
public final void registerBuffer(top.focess.command.DataConverter<?> dataConverter, top.focess.command.DataCollection.BufferGetter bufferGetter)Register the getter of the buffer- Parameters:
dataConverter- the buffer data converterbufferGetter- the getter of the buffer- See Also:
DataCollection.register(Plugin, DataConverter, top.focess.command.DataCollection.BufferGetter)
-
getAuthor
public final String getAuthor()
-
getVersion
public final top.focess.util.version.Version getVersion()
-
getLangConfig
public final LangConfig getLangConfig()
-
getDefaultConfig
public final DefaultConfig getDefaultConfig()
-
getPluginDescription
public final PluginDescription getPluginDescription()
-
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 theenable()method- Throws:
PluginUnloadException- to indicate that the plugin should be unloaded
-
registerSpecialArgumentComplexHandler
public final void registerSpecialArgumentComplexHandler(String name, SpecialArgumentComplexHandler handler)
Register the special argument handler- Parameters:
name- the name of the special argument handlerhandler- the special argument handler- See Also:
CommandLine.register(Plugin, String, SpecialArgumentComplexHandler)
-
serialize
public @Nullable Map<String,Object> serialize()
- Specified by:
serializein interfacetop.focess.util.serialize.FocessSerializable
-
getFile
public @Nullable File getFile()
Get the plugin jar file- Returns:
- the plugin jar file or null if it is not loaded from PluginClassLoader (the MainPlugin)
-
isInitialized
public boolean isInitialized()
Indicate whether the plugin is initialized or not- Returns:
- true if the plugin is initialized, false otherwise
-
initialize
public void initialize()
-
-