mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-02 12:50:16 +08:00
update new plugindes loader
This commit is contained in:
parent
1dba6601f3
commit
afe0b0e46e
@ -147,50 +147,20 @@ class PluginDescription(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun readFromContent(content_: String): PluginDescription {
|
fun readFromContent(content_: String): PluginDescription {
|
||||||
val content = content_.split("\n")
|
with(Config.load(content_)){
|
||||||
|
try {
|
||||||
var name = "Plugin"
|
|
||||||
var author = "Unknown"
|
|
||||||
var basePath = "net.mamoe.mirai.PluginMain"
|
|
||||||
var info = "Unknown"
|
|
||||||
var version = "1.0.0"
|
|
||||||
val depends = mutableListOf<String>();
|
|
||||||
|
|
||||||
content.forEach {
|
|
||||||
val line = it.trim()
|
|
||||||
val lowercaseLine = line.toLowerCase()
|
|
||||||
if (it.contains(":")) {
|
|
||||||
when {
|
|
||||||
lowercaseLine.startsWith("name") -> {
|
|
||||||
name = line.substringAfter(":").trim()
|
|
||||||
}
|
|
||||||
lowercaseLine.startsWith("author") -> {
|
|
||||||
author = line.substringAfter(":").trim()
|
|
||||||
}
|
|
||||||
lowercaseLine.startsWith("info") || lowercaseLine.startsWith("information") -> {
|
|
||||||
info = line.substringAfter(":").trim()
|
|
||||||
}
|
|
||||||
lowercaseLine.startsWith("main") || lowercaseLine.startsWith("path") || lowercaseLine.startsWith(
|
|
||||||
"basepath"
|
|
||||||
) -> {
|
|
||||||
basePath = line.substringAfter(":").trim()
|
|
||||||
}
|
|
||||||
lowercaseLine.startsWith("version") || lowercaseLine.startsWith("ver") -> {
|
|
||||||
version = line.substringAfter(":").trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (line.startsWith("-")) {
|
|
||||||
depends.add(line.substringAfter("-").trim())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PluginDescription(
|
return PluginDescription(
|
||||||
name,
|
this.getString("name"),
|
||||||
author,
|
this.getString("author"),
|
||||||
basePath,
|
this.getString("path"),
|
||||||
version,
|
this.getString("version"),
|
||||||
info,
|
this.getString("info"),
|
||||||
depends
|
this.getStringList("depends")
|
||||||
)
|
)
|
||||||
|
}catch (e:Exception){
|
||||||
|
error("Failed to read Plugin.YML")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,6 +208,7 @@ object PluginManager {
|
|||||||
if (pluginYml == null) {
|
if (pluginYml == null) {
|
||||||
logger.info("plugin.yml not found in jar " + jar.name + ", it will not be consider as a Plugin")
|
logger.info("plugin.yml not found in jar " + jar.name + ", it will not be consider as a Plugin")
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
val description =
|
val description =
|
||||||
PluginDescription.readFromContent(
|
PluginDescription.readFromContent(
|
||||||
URL("jar:file:" + file.absoluteFile + "!/" + pluginYml.name).openConnection().inputStream.use {
|
URL("jar:file:" + file.absoluteFile + "!/" + pluginYml.name).openConnection().inputStream.use {
|
||||||
@ -245,6 +216,9 @@ object PluginManager {
|
|||||||
})
|
})
|
||||||
pluginsFound[description.name] = description
|
pluginsFound[description.name] = description
|
||||||
pluginsLocation[description.name] = file
|
pluginsLocation[description.name] = file
|
||||||
|
}catch (e:Exception){
|
||||||
|
logger.info(e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user