Add Plugin.name, Plugin.version, etc. API mappings for PluginDescription

This commit is contained in:
Him188 2020-09-02 21:46:51 +08:00
parent ddd481b67c
commit fa79255864

View File

@ -11,16 +11,15 @@
package net.mamoe.mirai.console.plugin package net.mamoe.mirai.console.plugin
import com.vdurmont.semver4j.Semver
import net.mamoe.mirai.console.command.CommandOwner import net.mamoe.mirai.console.command.CommandOwner
import net.mamoe.mirai.console.data.PluginConfig
import net.mamoe.mirai.console.data.PluginData
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.disable import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.disable
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.enable import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.enable
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader
import net.mamoe.mirai.console.plugin.description.PluginDependency
import net.mamoe.mirai.console.plugin.description.PluginDescription import net.mamoe.mirai.console.plugin.description.PluginDescription
import net.mamoe.mirai.console.plugin.description.PluginKind
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
import java.io.File
import java.nio.file.Path
/** /**
* 表示一个 mirai-console 插件. * 表示一个 mirai-console 插件.
@ -51,86 +50,39 @@ public interface Plugin : CommandOwner {
} }
/** /**
* 获取 * 获取 [PluginDescription]
*/ */
public inline val Plugin.description: PluginDescription get() = this.safeLoader.getDescription(this) public inline val Plugin.description: PluginDescription get() = this.safeLoader.getDescription(this)
/** /**
* 支持文件系统存储的扩展. * 获取 [PluginDescription.name`]
*
* @suppress 此接口只应由 [JvmPlugin] 继承
*
* @see JvmPlugin
*/ */
public interface PluginFileExtensions { public inline val Plugin.name: String get() = this.description.name
/**
* 数据目录路径
* @see PluginData
*/
public val dataFolderPath: Path
/** /**
* 数据目录. `dataFolderPath.toFile()` * 获取 [PluginDescription.version]
* @see PluginData
*/ */
public val dataFolder: File public inline val Plugin.version: Semver get() = this.description.version
/** /**
* 从数据目录获取一个文件. * 获取 [PluginDescription.kind]
* @see dataFolderPath
*/ */
@JvmDefault public inline val Plugin.kind: PluginKind get() = this.description.kind
public fun resolveDataFile(relativePath: String): File = dataFolderPath.resolve(relativePath).toFile()
/** /**
* 从数据目录获取一个文件. * 获取 [PluginDescription.info]
* @see dataFolderPath
*/ */
@JvmDefault public inline val Plugin.info: String get() = this.description.info
public fun resolveDataPath(relativePath: String): Path = dataFolderPath.resolve(relativePath)
/** /**
* 从数据目录获取一个文件. * 获取 [PluginDescription.author]
* @see dataFolderPath
*/ */
@JvmDefault public inline val Plugin.author: String get() = this.description.author
public fun resolveDataFile(relativePath: Path): File = dataFolderPath.resolve(relativePath).toFile()
/** /**
* 从数据目录获取一个文件路径. * 获取 [PluginDescription.dependencies]
* @see dataFolderPath
*/ */
@JvmDefault public inline val Plugin.dependencies: List<PluginDependency> get() = this.description.dependencies
public fun resolveDataPath(relativePath: Path): Path = dataFolderPath.resolve(relativePath)
/**
* 插件配置保存路径
* @see PluginConfig
*/
public val configFolderPath: Path
/**
* 插件配置保存路径
* @see PluginConfig
*/
public val configFolder: File
/**
* 从配置目录获取一个文件.
* @see configFolderPath
*/
@JvmDefault
public fun resolveConfigFile(relativePath: String): File = configFolderPath.resolve(relativePath).toFile()
/**
* 从配置目录获取一个文件.
* @see configFolderPath
*/
@JvmDefault
public fun resolveConfigPath(relativePath: String): Path = configFolderPath.resolve(relativePath)
/** /**
* 从配置目录获取一个文件. * 从配置目录获取一个文件.