#36 Init SubServers.Console before SubAPI

This commit is contained in:
ME1312 2019-01-23 12:27:34 -05:00
parent 7158e0a3da
commit 975a12f3b6
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
5 changed files with 43 additions and 59 deletions

View File

@ -25,8 +25,9 @@ import java.util.*;
* SubAPI Class
*/
public final class SubAPI {
LinkedList<NamedContainer<Runnable, Runnable>> listeners = new LinkedList<NamedContainer<Runnable, Runnable>>();
LinkedList<Runnable> enableListeners = new LinkedList<Runnable>();
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
LinkedList<Runnable> disableListeners = new LinkedList<Runnable>();
private static HashMap<String, Object> knownSignatures = new HashMap<String, Object>();
boolean ready = false;
private final SubPlugin plugin;
@ -65,7 +66,8 @@ public final class SubAPI {
* @param disable An Event that will be called before SubAPI is disabled (your plugin should reset it's values in case this is a hard-reset instead of a shutdown)
*/
public void addListener(Runnable enable, Runnable disable) {
if (!Util.isNull(enable, disable)) listeners.add(new NamedContainer<Runnable, Runnable>(enable, disable));
if (enable != null) enableListeners.add(enable);
if (disable != null) disableListeners.add(disable);
}
/**

View File

@ -501,27 +501,15 @@ public final class SubPlugin extends BungeeCord implements Listener {
legServers.clear();
int plugins = 0;
List<?> listeners = (status)?api.reloadListeners:api.listeners;
List<Runnable> listeners = (status)?api.reloadListeners:api.enableListeners;
if (listeners.size() > 0) {
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading SubAPI Plugins...");
for (Object obj : listeners) {
if (status) {
try {
((Runnable) obj).run();
plugins++;
} catch (Throwable e) {
new InvocationTargetException(e, "Problem enabling plugin").printStackTrace();
}
} else {
NamedContainer<Runnable, Runnable> listener = (NamedContainer<Runnable, Runnable>) obj;
try {
if (listener.name() != null) {
listener.name().run();
plugins++;
}
} catch (Throwable e) {
new InvocationTargetException(e, "Problem enabling plugin").printStackTrace();
}
for (Runnable obj : listeners) {
try {
obj.run();
plugins++;
} catch (Throwable e) {
new InvocationTargetException(e, "Problem " + ((status)?"reloading":"enabling") + " plugin").printStackTrace();
}
}
}
@ -590,11 +578,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
try {
legServers.clear();
legServers.putAll(getServers());
if (api.listeners.size() > 0) {
if (api.disableListeners.size() > 0) {
System.out.println("SubServers > Resetting SubAPI Plugins...");
for (NamedContainer<Runnable, Runnable> listener : api.listeners) {
for (Runnable listener : api.disableListeners) {
try {
if (listener.get() != null) listener.get().run();
listener.run();
} catch (Throwable e) {
new InvocationTargetException(e, "Problem disabling plugin").printStackTrace();
}
@ -697,7 +685,6 @@ public final class SubPlugin extends BungeeCord implements Listener {
/**
* Emulate BungeeCord's getServers()
*
* @see SubAPI#getServers()
* @return Server Map
*/
@Override

View File

@ -1,4 +1,4 @@
name: SubServers-Console
main: net.ME1312.SubServers.Console.ConsolePlugin
version: 2.13.2a
version: 2.13.2b
author: ME1312

View File

@ -25,53 +25,47 @@ public final class ConsolePlugin extends Plugin implements Listener {
public HashMap<String, ConsoleWindow> cCurrent = new HashMap<String, ConsoleWindow>();
public HashMap<String, ConsoleWindow> sCurrent = new HashMap<String, ConsoleWindow>();
public YAMLConfig config;
public boolean init = false;
@Override
public void onEnable() {
SubAPI.getInstance().addListener(new Runnable() {
reload();
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.POPOUT(this, "popout"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.AUTO_POPOUT(this, "apopout"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.AUTO_POPOUT(this, "autopopout"));
new Metrics(this);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new JFrame("SubServers 2");
} catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
e.printStackTrace();
}
SubAPI.getInstance().addListener(null, new Runnable() {
@Override
public void run() {
enable();
reload();
}
}, new Runnable() {
@Override
public void run() {
disable();
}
});
}, null);
}
public void enable() {
try {this.
getDataFolder().mkdirs();
private void reload() {
try {
this.getDataFolder().mkdirs();
config = new YAMLConfig(new File(getDataFolder(), "config.yml"));
boolean save = false;
if (!config.get().getKeys().contains("Enabled-Servers")) {
config.get().set("Enabled-Servers", Collections.emptyList());
save = true;
} if (!config.get().getKeys().contains("Enabled-Creators")) {
}
if (!config.get().getKeys().contains("Enabled-Creators")) {
config.get().set("Enabled-Creators", Collections.emptyList());
save = true;
}
if (save) config.save();
if (!init) {
init = true;
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.POPOUT(this, "popout"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.AUTO_POPOUT(this, "autopopout"));
new Metrics(this);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new JFrame("SubServers 2");
} catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
@ -126,7 +120,8 @@ public final class ConsolePlugin extends Plugin implements Listener {
}
}
public void disable() {
@Override
public void onDisable() {
for (ConsoleWindow window : sCurrent.values()) {
window.destroy();
}

View File

@ -372,11 +372,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
}
public void connect(ServerContainer server, String address) {
server.setSubData(address);
if (server != null) server.setSubData(address);
}
public void disconnect(ServerContainer server) {
server.setSubData(null);
if (server != null) server.setSubData(null);
}
@EventHandler(priority = Byte.MIN_VALUE)