mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Fix inconsistent exceptions specified in docs and actually thrown.
This commit is contained in:
parent
8f61943c70
commit
73533c37cb
@ -20,6 +20,7 @@ import net.mamoe.mirai.console.internal.util.PluginServiceHelper.loadAllServices
|
||||
import net.mamoe.mirai.console.plugin.jvm.*
|
||||
import net.mamoe.mirai.console.plugin.loader.AbstractFilePluginLoader
|
||||
import net.mamoe.mirai.console.plugin.loader.PluginLoadException
|
||||
import net.mamoe.mirai.console.plugin.name
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.io.File
|
||||
@ -93,12 +94,17 @@ internal object BuiltInJvmPluginLoaderImpl :
|
||||
return filePlugins.toSet().map { it.value }
|
||||
}
|
||||
|
||||
private val loadedPlugins = ConcurrentHashMap<JvmPlugin, Unit>()
|
||||
|
||||
@Throws(PluginLoadException::class)
|
||||
override fun load(plugin: JvmPlugin) {
|
||||
ensureActive()
|
||||
|
||||
if (loadedPlugins.put(plugin, Unit) != null) {
|
||||
error("Plugin '${plugin.name}' is already loaded and cannot be reloaded.")
|
||||
}
|
||||
runCatching {
|
||||
check(plugin is JvmPluginInternal) { "A JvmPlugin must extend AbstractJvmPlugin" }
|
||||
check(plugin is JvmPluginInternal) { "A JvmPlugin must extend AbstractJvmPlugin to be loaded by JvmPluginLoader.BuiltIn" }
|
||||
plugin.internalOnLoad(plugin.componentStorage)
|
||||
}.getOrElse {
|
||||
throw PluginLoadException("Exception while loading ${plugin.description.name}", it)
|
||||
@ -106,7 +112,7 @@ internal object BuiltInJvmPluginLoaderImpl :
|
||||
}
|
||||
|
||||
override fun enable(plugin: JvmPlugin) {
|
||||
if (plugin.isEnabled) return
|
||||
if (plugin.isEnabled) error("Plugin '${plugin.name}' is already enabled and cannot be re-enabled.")
|
||||
ensureActive()
|
||||
runCatching {
|
||||
if (plugin is JvmPluginInternal) {
|
||||
@ -118,7 +124,7 @@ internal object BuiltInJvmPluginLoaderImpl :
|
||||
}
|
||||
|
||||
override fun disable(plugin: JvmPlugin) {
|
||||
if (!plugin.isEnabled) return
|
||||
if (!plugin.isEnabled) error("Plugin '${plugin.name}' is not already disabled and cannot be re-disabled.")
|
||||
|
||||
if (MiraiConsole.isActive)
|
||||
ensureActive()
|
||||
|
@ -76,7 +76,7 @@ public interface PluginLoader<P : Plugin, D : PluginDescription> {
|
||||
* @throws PluginLoadException 在加载插件遇到意料之中的错误时抛出 (如找不到主类等).
|
||||
* @throws IllegalStateException 在插件已经被加载时抛出. 这属于意料之外的情况.
|
||||
*/
|
||||
@Throws(PluginLoadException::class)
|
||||
@Throws(IllegalStateException::class, PluginLoadException::class)
|
||||
public fun load(plugin: P)
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user