Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
298d0139
Commit
298d0139
authored
Jan 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
bbe3bf65
c4f55f3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
mirai-console/src/main/kotlin/MiraiConsole.kt
mirai-console/src/main/kotlin/MiraiConsole.kt
+4
-0
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
...sole/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
+24
-2
No files found.
mirai-console/src/main/kotlin/MiraiConsole.kt
View file @
298d0139
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.plugin.PluginManager
import
kotlin.concurrent.thread
fun
main
()
{
...
...
@@ -42,6 +43,9 @@ fun main() {
}
}
PluginManager
.
loadPlugins
()
}
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
View file @
298d0139
package
net.mamoe.mirai.plugin
import
net.mamoe.mirai.utils.DefaultLogger
import
java.io.BufferedReader
import
java.io.File
import
java.io.InputStream
import
java.io.InputStreamReader
import
java.net.JarURLConnection
import
java.net.URL
import
java.util.jar.JarFile
...
...
@@ -49,6 +54,10 @@ class PluginDescription(
internal
var
noCircularDepend
:
Boolean
=
true
)
{
override
fun
toString
():
String
{
return
"name: $pluginName\nauthor: $pluginAuthor\npath: $pluginBasePath\nver: $pluginVersion\ninfo: $pluginInfo\ndepends: $depends"
}
companion
object
{
fun
readFromContent
(
content_
:
String
):
PluginDescription
{
val
content
=
content_
.
split
(
"\n"
)
...
...
@@ -116,11 +125,23 @@ object PluginManager{
if
(
file
!=
null
)
{
if
(
file
.
extension
==
"jar"
)
{
val
jar
=
JarFile
(
file
)
val
pluginYml
=
jar
.
entries
().
asIterator
().
asSequence
().
filter
{
it
.
name
.
toLowerCase
().
contains
(
"resource/plugin.yml"
)
}.
firstOrNull
()
val
pluginYml
=
jar
.
entries
().
asSequence
().
filter
{
it
.
name
.
toLowerCase
().
contains
(
"plugin.yml"
)
}.
firstOrNull
()
if
(
pluginYml
==
null
)
{
logger
.
info
(
"plugin.yml not found in jar "
+
jar
.
name
+
", it will not be consider as a Plugin"
)
}
else
{
val
description
=
PluginDescription
.
readFromContent
(
pluginYml
.
extra
.
toString
())
val
url
=
URL
(
"jar:file:"
+
file
.
absoluteFile
+
"!/"
+
pluginYml
.
name
)
val
jarConnection
:
JarURLConnection
=
url
.
openConnection
()
as
JarURLConnection
val
inputStream
:
InputStream
=
jarConnection
.
getInputStream
()
val
br
=
BufferedReader
(
InputStreamReader
(
inputStream
,
"UTF-8"
))
var
con
:
String
?
val
sb
=
StringBuffer
()
while
(
br
.
readLine
().
also
{
con
=
it
}
!=
null
)
{
sb
.
append
(
con
).
append
(
"\n"
)
}
val
description
=
PluginDescription
.
readFromContent
(
sb
.
toString
())
println
(
description
)
pluginsFound
[
description
.
pluginName
]
=
description
pluginsLocation
[
description
.
pluginName
]
=
jar
}
...
...
@@ -206,6 +227,7 @@ object PluginManager{
}
}
}
catch
(
e
:
ClassNotFoundException
)
{
e
.
printStackTrace
()
return
false
.
also
{
logger
.
error
(
"failed to load plugin "
+
description
.
pluginName
+
" , Main class not found under "
+
description
.
pluginBasePath
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment