mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-09 11:30:11 +08:00
plugin supporting
This commit is contained in:
parent
aa427c20de
commit
9e0251e668
@ -21,6 +21,10 @@ fun main() {
|
||||
thread { processNextCommandLine() }
|
||||
|
||||
PluginManager.loadPlugins()
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(thread {
|
||||
PluginManager.disableAllPlugins()
|
||||
})
|
||||
}
|
||||
|
||||
tailrec fun processNextCommandLine() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.mamoe.mirai.plugin
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.io.encodeToString
|
||||
import java.io.File
|
||||
@ -14,22 +13,27 @@ abstract class PluginBase constructor() {
|
||||
File(PluginManager.pluginsPath + pluginDescription.name).also { it.mkdir() }
|
||||
}
|
||||
|
||||
/**
|
||||
* 当一个插件被加载时调用
|
||||
*/
|
||||
open fun onLoad() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当所有插件全部被加载后被调用
|
||||
*/
|
||||
open fun onEnable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当插件关闭前被调用
|
||||
*/
|
||||
open fun onDisable() {
|
||||
|
||||
}
|
||||
|
||||
open fun onBotAdd(bot: Bot) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private lateinit var pluginDescription: PluginDescription
|
||||
|
||||
@ -235,6 +239,12 @@ object PluginManager {
|
||||
}
|
||||
|
||||
|
||||
fun disableAllPlugins() {
|
||||
nameToPluginBaseMap.values.forEach {
|
||||
it.onDisable()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,5 +15,6 @@ public class ImagePluginMain extends PluginBase {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
System.out.println("Enabled");
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user