diff --git a/bin/TestPlugin.jar b/bin/TestPlugin.jar new file mode 100644 index 0000000..4d3199f Binary files /dev/null and b/bin/TestPlugin.jar differ diff --git a/manifest b/manifest new file mode 100644 index 0000000..58ee908 --- /dev/null +++ b/manifest @@ -0,0 +1 @@ +Main-Class: TestPlugin diff --git a/plugins/TestPlugin.jar b/plugins/TestPlugin.jar new file mode 100644 index 0000000..4d3199f Binary files /dev/null and b/plugins/TestPlugin.jar differ diff --git a/plugins/TestPlugin.java b/plugins/TestPlugin.java index 2242da1..8849f5a 100644 --- a/plugins/TestPlugin.java +++ b/plugins/TestPlugin.java @@ -1,3 +1,5 @@ public class TestPlugin { - + public TestPlugin() { + System.out.println("Loaded me!"); + } } diff --git a/src/sig/PluginLoader.java b/src/sig/PluginLoader.java index c4d8ef2..392110d 100644 --- a/src/sig/PluginLoader.java +++ b/src/sig/PluginLoader.java @@ -1,6 +1,10 @@ package sig; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; @@ -8,9 +12,22 @@ public class PluginLoader { public static void LoadPlugins() { Path p = Path.of("..","plugins"); try { - Files.walk(p).filter((f)->Files.isRegularFile(f)).forEach((f)->{System.out.println("Found "+f);}); + Files.walk(p).filter((f)->Files.isRegularFile(f)&&f.getFileName().toString().contains(".jar")).forEach((f)->{ + LoadPlugin(f); + }); } catch (IOException e) { e.printStackTrace(); } } + + private static void LoadPlugin(Path f) { + try { + System.out.println("Loading "+f); + URL l = f.toUri().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[]{l}); + Object newPlugin = Class.forName(f.getFileName().toString().replace(".jar",""),true,loader).getDeclaredConstructor().newInstance(); + } catch (MalformedURLException | InstantiationException | IllegalAccessException | ClassNotFoundException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } }