Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
3c361b43
Commit
3c361b43
authored
Jun 22, 2022
by
KingRainbow44
Browse files
Fix method of loading dependant plugins
parent
5a8b76d9
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/plugin/PluginManager.java
View file @
3c361b43
...
@@ -108,7 +108,7 @@ public final class PluginManager {
...
@@ -108,7 +108,7 @@ public final class PluginManager {
fileReader
.
close
();
fileReader
.
close
();
// Check if the plugin has alternate dependencies.
// 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.
// Add the plugin to a "load later" list.
dependencies
.
add
(
new
PluginData
(
dependencies
.
add
(
new
PluginData
(
pluginInstance
,
PluginIdentifier
.
fromPluginConfig
(
pluginConfig
),
pluginInstance
,
PluginIdentifier
.
fromPluginConfig
(
pluginConfig
),
...
@@ -130,20 +130,30 @@ public final class PluginManager {
...
@@ -130,20 +130,30 @@ public final class PluginManager {
// Load plugins with dependencies.
// Load plugins with dependencies.
int
depth
=
0
;
final
int
maxDepth
=
30
;
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
{
try
{
// Get the next plugin to load.
// Get the next plugin to load.
var
pluginData
=
dependencies
.
get
(
0
);
var
pluginData
=
dependencies
.
get
(
0
);
// Check if the plugin's dependencies are loaded.
// Check if the plugin's dependencies are loaded.
if
(!
this
.
plugins
.
keySet
().
containsAll
(
List
.
of
(
pluginData
.
getDependencies
())))
{
if
(!
this
.
plugins
.
keySet
().
containsAll
(
List
.
of
(
pluginData
.
getDependencies
())))
{
depth
++;
// Increase depth counter.
depth
++;
// Increase depth counter.
continue
;
// Continue to next plugin.
continue
;
// Continue to next plugin.
}
}
// Remove the plugin from the list of dependencies.
dependencies
.
remove
(
pluginData
);
// Load the plugin.
// Load the plugin.
this
.
loadPlugin
(
pluginData
.
getPlugin
(),
pluginData
.
getIdentifier
(),
pluginData
.
getClassLoader
());
this
.
loadPlugin
(
pluginData
.
getPlugin
(),
pluginData
.
getIdentifier
(),
pluginData
.
getClassLoader
());
}
catch
(
Exception
exception
)
{
}
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 {
...
@@ -175,7 +185,7 @@ public final class PluginManager {
// Call the plugin's onLoad method.
// Call the plugin's onLoad method.
try
{
try
{
plugin
.
onLoad
();
plugin
.
onLoad
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load plugin: "
+
identifier
.
name
,
exception
);
Grasscutter
.
getLogger
().
error
(
"Failed to load plugin: "
+
identifier
.
name
,
exception
);
}
}
}
}
...
@@ -188,7 +198,7 @@ public final class PluginManager {
...
@@ -188,7 +198,7 @@ public final class PluginManager {
Grasscutter
.
getLogger
().
info
(
"Enabling plugin: "
+
name
);
Grasscutter
.
getLogger
().
info
(
"Enabling plugin: "
+
name
);
try
{
try
{
plugin
.
onEnable
();
plugin
.
onEnable
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to enable plugin: "
+
name
,
exception
);
Grasscutter
.
getLogger
().
error
(
"Failed to enable plugin: "
+
name
,
exception
);
}
}
});
});
...
@@ -202,7 +212,7 @@ public final class PluginManager {
...
@@ -202,7 +212,7 @@ public final class PluginManager {
Grasscutter
.
getLogger
().
info
(
"Disabling plugin: "
+
name
);
Grasscutter
.
getLogger
().
info
(
"Disabling plugin: "
+
name
);
try
{
try
{
plugin
.
onDisable
();
plugin
.
onDisable
();
}
catch
(
Exception
exception
)
{
}
catch
(
Throwable
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to disable plugin: "
+
name
,
exception
);
Grasscutter
.
getLogger
().
error
(
"Failed to disable plugin: "
+
name
,
exception
);
}
}
});
});
...
...
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