Commit 37b280d4 authored by Him188's avatar Him188

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
parents bfc964f4 28e8c5d0
......@@ -21,6 +21,10 @@ fun main() {
thread { processNextCommandLine() }
PluginManager.loadPlugins()
Runtime.getRuntime().addShutdownHook(thread {
PluginManager.disableAllPlugins()
})
}
tailrec fun processNextCommandLine() {
......
package net.mamoe.mirai.plugin
import kotlinx.coroutines.CoroutineScope
import net.mamoe.mirai.Bot
import net.mamoe.mirai.utils.DefaultLogger
import net.mamoe.mirai.utils.io.encodeToString
import java.io.File
......@@ -19,22 +18,27 @@ abstract class PluginBase : CoroutineScope {
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
......@@ -236,6 +240,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");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment