diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt index 43fabd034..a9b5b039c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt @@ -15,6 +15,8 @@ import kotlinx.coroutines.* import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.data.runCatchingLog import net.mamoe.mirai.console.internal.data.mkdir +import net.mamoe.mirai.console.permission.ExperimentalPermission +import net.mamoe.mirai.console.permission.Identifier import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.PluginManager import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader @@ -41,7 +43,13 @@ internal abstract class JvmPluginInternal( final override var isEnabled: Boolean = false private val resourceContainerDelegate by lazy { this::class.java.classLoader.asResourceContainer() } - override fun getResourceAsStream(path: String): InputStream? = resourceContainerDelegate.getResourceAsStream(path) + final override fun getResourceAsStream(path: String): InputStream? = + resourceContainerDelegate.getResourceAsStream(path) + + @OptIn(ExperimentalPermission::class) + override fun allocate(identifierString: String): Identifier { + return Identifier(description.name) + } // region JvmPlugin final override val logger: MiraiLogger by lazy { @@ -62,11 +70,11 @@ internal abstract class JvmPluginInternal( dataFolderPath.toFile() } - override val configFolderPath: Path by lazy { + final override val configFolderPath: Path by lazy { PluginManager.pluginsConfigPath.resolve(description.name).apply { mkdir() } } - override val configFolder: File by lazy { + final override val configFolder: File by lazy { configFolderPath.toFile() } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt index 4bec6f753..9f0f1c7b9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt @@ -159,6 +159,13 @@ internal object PluginManagerImpl : PluginManager, CoroutineScope by MiraiConsol } } + @kotlin.jvm.Throws(PluginLoadException::class) + internal fun checkPluginDescription(description: PluginDescription) { + when (description.name.toLowerCase()) { + "main", "console", "plugin", "config", "data" -> throw PluginLoadException("Plugin name '${description.name}' is forbidden.") + } + } + /** * @return [builtInLoaders] 可以加载的插件. 已经完成了 [PluginLoader.load], 但没有 [PluginLoader.enable] */ @@ -171,6 +178,7 @@ internal object PluginManagerImpl : PluginManager, CoroutineScope by MiraiConsol .onEach { (loader, descriptions) -> loader as PluginLoader + descriptions.forEach(PluginManagerImpl::checkPluginDescription) descriptions.filter { it.kind == PluginKind.LOADER }.sortByDependencies().loadAndEnableAllInOrder() } .flatMap { it.second.asSequence() } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt index a5f259502..64e9058f2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt @@ -27,7 +27,14 @@ public interface PluginDescription { public val kind: PluginKind /** - * 插件名称. 不允许存在 ":" + * 插件名称. 不允许存在 ":". + * + * 插件名称不能完全是以下其中一种. + * - console + * - main + * - plugin + * - config + * - data */ public val name: String