mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 17:00:14 +08:00
Check forbidden plugin names
This commit is contained in:
parent
9add8f71ef
commit
52d417ad0e
@ -15,6 +15,8 @@ import kotlinx.coroutines.*
|
|||||||
import net.mamoe.mirai.console.MiraiConsole
|
import net.mamoe.mirai.console.MiraiConsole
|
||||||
import net.mamoe.mirai.console.data.runCatchingLog
|
import net.mamoe.mirai.console.data.runCatchingLog
|
||||||
import net.mamoe.mirai.console.internal.data.mkdir
|
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.Plugin
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager
|
import net.mamoe.mirai.console.plugin.PluginManager
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader
|
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader
|
||||||
@ -41,7 +43,13 @@ internal abstract class JvmPluginInternal(
|
|||||||
final override var isEnabled: Boolean = false
|
final override var isEnabled: Boolean = false
|
||||||
|
|
||||||
private val resourceContainerDelegate by lazy { this::class.java.classLoader.asResourceContainer() }
|
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
|
// region JvmPlugin
|
||||||
final override val logger: MiraiLogger by lazy {
|
final override val logger: MiraiLogger by lazy {
|
||||||
@ -62,11 +70,11 @@ internal abstract class JvmPluginInternal(
|
|||||||
dataFolderPath.toFile()
|
dataFolderPath.toFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val configFolderPath: Path by lazy {
|
final override val configFolderPath: Path by lazy {
|
||||||
PluginManager.pluginsConfigPath.resolve(description.name).apply { mkdir() }
|
PluginManager.pluginsConfigPath.resolve(description.name).apply { mkdir() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val configFolder: File by lazy {
|
final override val configFolder: File by lazy {
|
||||||
configFolderPath.toFile()
|
configFolderPath.toFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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]
|
* @return [builtInLoaders] 可以加载的插件. 已经完成了 [PluginLoader.load], 但没有 [PluginLoader.enable]
|
||||||
*/
|
*/
|
||||||
@ -171,6 +178,7 @@ internal object PluginManagerImpl : PluginManager, CoroutineScope by MiraiConsol
|
|||||||
.onEach { (loader, descriptions) ->
|
.onEach { (loader, descriptions) ->
|
||||||
loader as PluginLoader<Plugin, PluginDescription>
|
loader as PluginLoader<Plugin, PluginDescription>
|
||||||
|
|
||||||
|
descriptions.forEach(PluginManagerImpl::checkPluginDescription)
|
||||||
descriptions.filter { it.kind == PluginKind.LOADER }.sortByDependencies().loadAndEnableAllInOrder()
|
descriptions.filter { it.kind == PluginKind.LOADER }.sortByDependencies().loadAndEnableAllInOrder()
|
||||||
}
|
}
|
||||||
.flatMap { it.second.asSequence() }
|
.flatMap { it.second.asSequence() }
|
||||||
|
@ -27,7 +27,14 @@ public interface PluginDescription {
|
|||||||
public val kind: PluginKind
|
public val kind: PluginKind
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件名称. 不允许存在 ":"
|
* 插件名称. 不允许存在 ":".
|
||||||
|
*
|
||||||
|
* 插件名称不能完全是以下其中一种.
|
||||||
|
* - console
|
||||||
|
* - main
|
||||||
|
* - plugin
|
||||||
|
* - config
|
||||||
|
* - data
|
||||||
*/
|
*/
|
||||||
public val name: String
|
public val name: String
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user