Skip to content

Commit

Permalink
PluginManager: fix #119
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Jan 14, 2021
1 parent 72c5e24 commit caf5a29
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/kotlin/org/itxtech/mirainative/manager/PluginManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ object PluginManager {
fun unloadPlugins(): Job {
MiraiNative.logger.info("正停用所有插件并调用Exit事件。")
return MiraiNative.nativeLaunch {
plugins.values.forEach {
unloadPlugin(it)
val it = plugins.values.iterator()
while (it.hasNext()) {
val p = it.next()
unloadPlugin(p, false)
it.remove()
}
plugins.clear()
}
Expand Down Expand Up @@ -140,7 +143,7 @@ object PluginManager {
}
}

fun unloadPlugin(plugin: NativePlugin) {
fun unloadPlugin(plugin: NativePlugin, remove: Boolean = true) {
with(plugin) {
if (loaded) {
disablePlugin(this)
Expand All @@ -153,7 +156,7 @@ object PluginManager {
entries.clear()
events.clear()
tempFile?.delete()
plugins.remove(id)
if (remove) plugins.remove(id)
Tray.update()
}
}
Expand Down

0 comments on commit caf5a29

Please sign in to comment.