forked from BLOCKFANTASY/LOOHP-Limbo
Merge pull request #88 from Kas-tle/feature/prefer-limbo-yml
Prefer use of limbo.yml for plugin loading
This commit is contained in:
commit
94ad6d8460
|
|
@ -55,18 +55,35 @@ public class PluginManager {
|
|||
protected void loadPlugins() {
|
||||
for (File file : pluginFolder.listFiles()) {
|
||||
if (file.isFile() && file.getName().endsWith(".jar")) {
|
||||
boolean found = false;
|
||||
try (ZipInputStream zip = new ZipInputStream(new FileInputStream(file))) {
|
||||
ZipEntry limboYmlEntry = null;
|
||||
ZipEntry pluginYmlEntry = null;
|
||||
|
||||
while (true) {
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
if (entry == null) {
|
||||
break;
|
||||
}
|
||||
String name = entry.getName();
|
||||
if (name.endsWith("plugin.yml") || name.endsWith("limbo.yml")) {
|
||||
found = true;
|
||||
if (name.endsWith("limbo.yml")) {
|
||||
limboYmlEntry = entry;
|
||||
} else if (name.endsWith("plugin.yml")) {
|
||||
pluginYmlEntry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration pluginYaml = new FileConfiguration(zip);
|
||||
ZipEntry chosenEntry = limboYmlEntry != null ? limboYmlEntry : pluginYmlEntry;
|
||||
|
||||
if (chosenEntry != null) {
|
||||
try (ZipInputStream processZip = new ZipInputStream(new FileInputStream(file))) {
|
||||
while (true) {
|
||||
ZipEntry currentEntry = processZip.getNextEntry();
|
||||
if (currentEntry == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentEntry.getName().equals(chosenEntry.getName())) {
|
||||
FileConfiguration pluginYaml = new FileConfiguration(processZip);
|
||||
String main = pluginYaml.get("main", String.class);
|
||||
String pluginName = pluginYaml.get("name", String.class);
|
||||
|
||||
|
|
@ -74,6 +91,7 @@ public class PluginManager {
|
|||
System.err.println("Ambiguous plugin name in " + file.getName() + " with the plugin \"" + plugins.get(pluginName).getClass().getName() + "\"");
|
||||
break;
|
||||
}
|
||||
|
||||
URLClassLoader child = new URLClassLoader(new URL[]{file.toURI().toURL()}, Limbo.getInstance().getClass().getClassLoader());
|
||||
Class<?> clazz = Class.forName(main, true, child);
|
||||
LimboPlugin plugin = (LimboPlugin) clazz.getDeclaredConstructor().newInstance();
|
||||
|
|
@ -84,13 +102,14 @@ public class PluginManager {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Jar file " + file.getName() + " has no plugin.yml or limbo.yml!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Unable to load plugin \"" + file.getName() + "\"");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!found) {
|
||||
System.err.println("Jar file " + file.getName() + " has no plugin.yml!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue