File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
src/main/java/org/hydev/mcpm/client/injector Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,16 @@ public interface LoadBoundary
14
14
* Dynamically load a local plugin through JVM reflections and classloader hacks
15
15
*
16
16
* @param name Loaded plugin name
17
+ * @return True if success, false if failed
18
+ * @throws PluginNotFoundException Plugin of the name is not found in the plugins directory
17
19
*/
18
- public void loadPlugin (String name ) throws PluginNotFoundException ;
20
+ public boolean loadPlugin (String name ) throws PluginNotFoundException ;
19
21
20
22
/**
21
23
* Dynamically load a local plugin through JVM reflections and classloader hacks
22
24
*
23
25
* @param jar Local jar file path
26
+ * @return True if success, false if failed
24
27
*/
25
- public void loadPlugin (File jar );
28
+ public boolean loadPlugin (File jar );
26
29
}
Original file line number Diff line number Diff line change 29
29
public class PluginLoader implements LoadBoundary , UnloadBoundary , ReloadBoundary
30
30
{
31
31
@ Override
32
- public void loadPlugin (String name ) throws PluginNotFoundException
32
+ public boolean loadPlugin (String name ) throws PluginNotFoundException
33
33
{
34
34
// 1. Find plugin file by name
35
35
var nf = new PluginNotFoundException (name );
@@ -45,28 +45,30 @@ public void loadPlugin(String name) throws PluginNotFoundException
45
45
catch (IOException ignored ) { return false ; }
46
46
}).findFirst ().orElseThrow (() -> nf );
47
47
48
- loadPlugin (file );
48
+ return loadPlugin (file );
49
49
}
50
50
51
51
@ Override
52
- public void loadPlugin (File jar )
52
+ public boolean loadPlugin (File jar )
53
53
{
54
54
// 2. Load plugin
55
55
var pm = Bukkit .getPluginManager ();
56
56
try
57
57
{
58
58
var plugin = pm .loadPlugin (jar );
59
- assert plugin != null ;
59
+ if ( plugin == null ) return false ;
60
60
61
61
// 3. Call onLoad()
62
62
plugin .onLoad ();
63
63
pm .enablePlugin (plugin );
64
+ return true ;
64
65
}
65
66
catch (InvalidPluginException | InvalidDescriptionException e )
66
67
{
67
68
// These are errors indicating that the plugin we're trying to load is badly formatted.
68
69
// There are nothing we can do.
69
70
e .printStackTrace ();
71
+ return false ;
70
72
}
71
73
}
72
74
You can’t perform that action at this time.
0 commit comments