Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
3c361b43
Commit
3c361b43
authored
3 years ago
by
KingRainbow44
Browse files
Options
Downloads
Patches
Plain Diff
Fix method of loading dependant plugins
parent
5a8b76d9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/emu/grasscutter/plugin/PluginManager.java
+16
-6
16 additions, 6 deletions
src/main/java/emu/grasscutter/plugin/PluginManager.java
with
16 additions
and
6 deletions
src/main/java/emu/grasscutter/plugin/PluginManager.java
+
16
−
6
View file @
3c361b43
...
...
@@ -108,7 +108,7 @@ public final class PluginManager {
fileReader
.
close
();
// Check if the plugin has alternate dependencies.
if
(
pluginConfig
.
loadAfter
.
length
>
0
)
{
if
(
pluginConfig
.
loadAfter
!=
null
&&
pluginConfig
.
loadAfter
.
length
>
0
)
{
// Add the plugin to a "load later" list.
dependencies
.
add
(
new
PluginData
(
pluginInstance
,
PluginIdentifier
.
fromPluginConfig
(
pluginConfig
),
...
...
@@ -130,20 +130,30 @@ public final class PluginManager {
// Load plugins with dependencies.
int
depth
=
0
;
final
int
maxDepth
=
30
;
while
(!
dependencies
.
isEmpty
()
||
depth
<
maxDepth
)
{
while
(!
dependencies
.
isEmpty
())
{
// Check if the depth is too high.
if
(
depth
>=
maxDepth
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load plugins with dependencies."
);
break
;
}
try
{
// Get the next plugin to load.
var
pluginData
=
dependencies
.
get
(
0
);
// Check if the plugin's dependencies are loaded.
if
(!
this
.
plugins
.
keySet
().
containsAll
(
List
.
of
(
pluginData
.
getDependencies
())))
{
depth
++;
// Increase depth counter.
continue
;
// Continue to next plugin.
}
// Remove the plugin from the list of dependencies.
dependencies
.
remove
(
pluginData
);
// Load the plugin.
this
.
loadPlugin
(
pluginData
.
getPlugin
(),
pluginData
.
getIdentifier
(),
pluginData
.
getClassLoader
());
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load a plugin."
,
exception
);
Grasscutter
.
getLogger
().
error
(
"Failed to load a plugin."
,
exception
);
depth
++;
}
}
}
...
...
@@ -175,7 +185,7 @@ public final class PluginManager {
// Call the plugin's onLoad method.
try
{
plugin
.
onLoad
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load plugin: "
+
identifier
.
name
,
exception
);
}
}
...
...
@@ -188,7 +198,7 @@ public final class PluginManager {
Grasscutter
.
getLogger
().
info
(
"Enabling plugin: "
+
name
);
try
{
plugin
.
onEnable
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to enable plugin: "
+
name
,
exception
);
}
});
...
...
@@ -202,7 +212,7 @@ public final class PluginManager {
Grasscutter
.
getLogger
().
info
(
"Disabling plugin: "
+
name
);
try
{
plugin
.
onDisable
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to disable plugin: "
+
name
,
exception
);
}
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment