mirror of https://github.com/LOOHP/Limbo.git
Fixed Access Control, Fixed PluginManager null during onLoad for LimboPlugins
This commit is contained in:
parent
e8f4e86b16
commit
bae75e0d0a
|
|
@ -9,6 +9,8 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
|
@ -286,6 +288,14 @@ public class Limbo {
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
pluginManager = new PluginManager(pluginFolder);
|
pluginManager = new PluginManager(pluginFolder);
|
||||||
|
try {
|
||||||
|
Method loadPluginsMethod = PluginManager.class.getDeclaredMethod("loadPlugins");
|
||||||
|
loadPluginsMethod.setAccessible(true);
|
||||||
|
loadPluginsMethod.invoke(pluginManager);
|
||||||
|
loadPluginsMethod.setAccessible(false);
|
||||||
|
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
for (LimboPlugin plugin : Limbo.getInstance().getPluginManager().getPlugins()) {
|
||||||
console.sendMessage("Enabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
console.sendMessage("Enabling plugin " + plugin.getName() + " " + plugin.getInfo().getVersion());
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ public class LimboPlugin {
|
||||||
private File dataFolder;
|
private File dataFolder;
|
||||||
private PluginInfo info;
|
private PluginInfo info;
|
||||||
|
|
||||||
public final void setInfo(FileConfiguration file) {
|
protected final void setInfo(FileConfiguration file) {
|
||||||
info = new PluginInfo(file);
|
info = new PluginInfo(file);
|
||||||
name = info.getName();
|
name = info.getName();
|
||||||
dataFolder = new File(Limbo.getInstance().getPluginFolder(), name);
|
dataFolder = new File(Limbo.getInstance().getPluginFolder(), name);
|
||||||
|
|
@ -29,19 +29,19 @@ public class LimboPlugin {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public final String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getDataFolder() {
|
public final File getDataFolder() {
|
||||||
return new File(dataFolder.getAbsolutePath());
|
return new File(dataFolder.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginInfo getInfo() {
|
public final PluginInfo getInfo() {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Limbo getServer() {
|
public final Limbo getServer() {
|
||||||
return Limbo.getInstance();
|
return Limbo.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,10 @@ public class PluginManager {
|
||||||
public PluginManager(File pluginFolder) {
|
public PluginManager(File pluginFolder) {
|
||||||
this.pluginFolder = pluginFolder;
|
this.pluginFolder = pluginFolder;
|
||||||
this.executors = new ArrayList<>();
|
this.executors = new ArrayList<>();
|
||||||
|
|
||||||
this.plugins = new LinkedHashMap<>();
|
this.plugins = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadPlugins() {
|
||||||
for (File file : pluginFolder.listFiles()) {
|
for (File file : pluginFolder.listFiles()) {
|
||||||
if (file.isFile() && file.getName().endsWith(".jar")) {
|
if (file.isFile() && file.getName().endsWith(".jar")) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
@ -54,12 +55,12 @@ public class PluginManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
URLClassLoader url = new URLClassLoader(new URL[] {file.toURI().toURL()});
|
URLClassLoader url = new URLClassLoader(new URL[] {file.toURI().toURL()});
|
||||||
Class<?> plugin = url.loadClass(main);
|
Class<?> clazz = url.loadClass(main);
|
||||||
LimboPlugin clazz = (LimboPlugin) plugin.getDeclaredConstructor().newInstance();
|
LimboPlugin plugin = (LimboPlugin) clazz.getDeclaredConstructor().newInstance();
|
||||||
clazz.setInfo(pluginYaml);
|
plugin.setInfo(pluginYaml);
|
||||||
plugins.put(clazz.getName(), clazz);
|
plugins.put(plugin.getName(), plugin);
|
||||||
clazz.onLoad();
|
plugin.onLoad();
|
||||||
Limbo.getInstance().getConsole().sendMessage("Loading plugin " + file.getName() + " " + clazz.getInfo().getVersion() + " by " + clazz.getInfo().getAuthor());
|
Limbo.getInstance().getConsole().sendMessage("Loading plugin " + file.getName() + " " + plugin.getInfo().getVersion() + " by " + plugin.getInfo().getAuthor());
|
||||||
url.close();
|
url.close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue