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
d38fa039
Commit
d38fa039
authored
Jan 18, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin supporting
parent
3eed99ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
19 deletions
+49
-19
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
...sole/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
+49
-19
No files found.
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
View file @
d38fa039
...
...
@@ -5,24 +5,36 @@ import java.io.File
import
java.util.jar.JarFile
abstract
class
PluginBase
{
abstract
class
PluginBase
constructor
()
{
open
fun
onLoad
(){
open
fun
onLoad
()
{
}
open
fun
onEnable
(){
open
fun
onEnable
()
{
}
open
fun
onDisable
(){
open
fun
onDisable
()
{
}
fun
getPluginManager
():
PluginManager
{
fun
getPluginManager
():
PluginManager
{
return
PluginManager
}
private
lateinit
var
pluginDescription
:
PluginDescription
internal
fun
init
(
pluginDescription
:
PluginDescription
)
{
this
.
pluginDescription
=
pluginDescription
this
.
onLoad
()
}
fun
getDataFolder
():
File
{
return
File
(
PluginManager
.
pluginsPath
+
pluginDescription
.
pluginName
).
also
{
it
.
mkdirs
()
}
}
}
...
...
@@ -33,9 +45,8 @@ class PluginDescription(
val
pluginVersion
:
String
,
val
pluginInfo
:
String
,
val
depends
:
List
<
String
>,
//插件的依赖
//internal
var
loaded
:
Boolean
=
false
,
var
noCircularDepend
:
Boolean
=
true
internal
var
loaded
:
Boolean
=
false
,
internal
var
noCircularDepend
:
Boolean
=
true
)
{
companion
object
{
...
...
@@ -81,23 +92,17 @@ class PluginDescription(
object
PluginManager
{
private
val
pluginsPath
=
System
.
getProperty
(
"user.dir"
)
+
"/plugins/"
.
replace
(
"//"
,
"/"
).
also
{
internal
val
pluginsPath
=
System
.
getProperty
(
"user.dir"
)
+
"/plugins/"
.
replace
(
"//"
,
"/"
).
also
{
File
(
it
).
mkdirs
()
}
private
val
logger
=
DefaultLogger
(
"Plugin Manager"
)
//已完成加载的
private
val
nameTo
DescriptionMap
:
Map
<
String
,
PluginDescription
>
=
mutableMapOf
()
private
val
pluginBaseToDescriptionMap
:
Map
<
PluginBase
,
PluginDescription
>
=
mutableMapOf
()
private
val
nameTo
PluginBaseMap
:
MutableMap
<
String
,
PluginBase
>
=
mutableMapOf
()
fun
getPluginDataFolder
(
plugin
:
PluginBase
):
File
{
val
name
=
(
pluginBaseToDescriptionMap
[
plugin
]
?:
error
(
"Plugin not loaded"
)).
pluginName
return
File
(
pluginsPath
+
name
).
also
{
it
.
mkdirs
()
}
}
/**
...
...
@@ -179,11 +184,36 @@ object PluginManager{
//在这里所有的depends都已经加载了
//loadPlugin
//real load
logger
.
info
(
"loading plugin "
+
description
.
pluginName
)
}
try
{
this
.
javaClass
.
classLoader
.
loadClass
(
description
.
pluginBasePath
)
return
try
{
val
subClass
=
javaClass
.
asSubclass
(
PluginBase
::
class
.
java
)
val
plugin
:
PluginBase
=
subClass
.
getDeclaredConstructor
().
newInstance
()
description
.
loaded
=
true
logger
.
info
(
"successfully loaded plugin "
+
description
.
pluginName
)
logger
.
info
(
description
.
pluginInfo
)
nameToPluginBaseMap
[
description
.
pluginName
]
=
plugin
plugin
.
init
(
description
)
true
}
catch
(
e
:
ClassCastException
)
{
false
.
also
{
logger
.
error
(
"failed to load plugin "
+
description
.
pluginName
+
" , Main class does not extends PluginBase "
)
}
}
}
catch
(
e
:
ClassNotFoundException
)
{
return
false
.
also
{
logger
.
error
(
"failed to load plugin "
+
description
.
pluginName
+
" , Main class not found under "
+
description
.
pluginBasePath
)
}
}
}
pluginsFound
.
values
.
forEach
{
loadPlugin
(
it
)
}
}
...
...
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