#36 Init SubServers.Console before SubAPI
This commit is contained in:
parent
7158e0a3da
commit
975a12f3b6
|
@ -25,8 +25,9 @@ import java.util.*;
|
||||||
* SubAPI Class
|
* SubAPI Class
|
||||||
*/
|
*/
|
||||||
public final class SubAPI {
|
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> reloadListeners = new LinkedList<Runnable>();
|
||||||
|
LinkedList<Runnable> disableListeners = new LinkedList<Runnable>();
|
||||||
private static HashMap<String, Object> knownSignatures = new HashMap<String, Object>();
|
private static HashMap<String, Object> knownSignatures = new HashMap<String, Object>();
|
||||||
boolean ready = false;
|
boolean ready = false;
|
||||||
private final SubPlugin plugin;
|
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)
|
* @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) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -501,27 +501,15 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||||
legServers.clear();
|
legServers.clear();
|
||||||
|
|
||||||
int plugins = 0;
|
int plugins = 0;
|
||||||
List<?> listeners = (status)?api.reloadListeners:api.listeners;
|
List<Runnable> listeners = (status)?api.reloadListeners:api.enableListeners;
|
||||||
if (listeners.size() > 0) {
|
if (listeners.size() > 0) {
|
||||||
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading SubAPI Plugins...");
|
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading SubAPI Plugins...");
|
||||||
for (Object obj : listeners) {
|
for (Runnable obj : listeners) {
|
||||||
if (status) {
|
try {
|
||||||
try {
|
obj.run();
|
||||||
((Runnable) obj).run();
|
plugins++;
|
||||||
plugins++;
|
} catch (Throwable e) {
|
||||||
} catch (Throwable e) {
|
new InvocationTargetException(e, "Problem " + ((status)?"reloading":"enabling") + " plugin").printStackTrace();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,11 +578,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||||
try {
|
try {
|
||||||
legServers.clear();
|
legServers.clear();
|
||||||
legServers.putAll(getServers());
|
legServers.putAll(getServers());
|
||||||
if (api.listeners.size() > 0) {
|
if (api.disableListeners.size() > 0) {
|
||||||
System.out.println("SubServers > Resetting SubAPI Plugins...");
|
System.out.println("SubServers > Resetting SubAPI Plugins...");
|
||||||
for (NamedContainer<Runnable, Runnable> listener : api.listeners) {
|
for (Runnable listener : api.disableListeners) {
|
||||||
try {
|
try {
|
||||||
if (listener.get() != null) listener.get().run();
|
listener.run();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
new InvocationTargetException(e, "Problem disabling plugin").printStackTrace();
|
new InvocationTargetException(e, "Problem disabling plugin").printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -697,7 +685,6 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||||
/**
|
/**
|
||||||
* Emulate BungeeCord's getServers()
|
* Emulate BungeeCord's getServers()
|
||||||
*
|
*
|
||||||
* @see SubAPI#getServers()
|
|
||||||
* @return Server Map
|
* @return Server Map
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name: SubServers-Console
|
name: SubServers-Console
|
||||||
main: net.ME1312.SubServers.Console.ConsolePlugin
|
main: net.ME1312.SubServers.Console.ConsolePlugin
|
||||||
version: 2.13.2a
|
version: 2.13.2b
|
||||||
author: ME1312
|
author: ME1312
|
|
@ -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> cCurrent = new HashMap<String, ConsoleWindow>();
|
||||||
public HashMap<String, ConsoleWindow> sCurrent = new HashMap<String, ConsoleWindow>();
|
public HashMap<String, ConsoleWindow> sCurrent = new HashMap<String, ConsoleWindow>();
|
||||||
public YAMLConfig config;
|
public YAMLConfig config;
|
||||||
public boolean init = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
enable();
|
reload();
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
disable();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
private void reload() {
|
||||||
try {this.
|
try {
|
||||||
getDataFolder().mkdirs();
|
this.getDataFolder().mkdirs();
|
||||||
config = new YAMLConfig(new File(getDataFolder(), "config.yml"));
|
config = new YAMLConfig(new File(getDataFolder(), "config.yml"));
|
||||||
boolean save = false;
|
boolean save = false;
|
||||||
if (!config.get().getKeys().contains("Enabled-Servers")) {
|
if (!config.get().getKeys().contains("Enabled-Servers")) {
|
||||||
config.get().set("Enabled-Servers", Collections.emptyList());
|
config.get().set("Enabled-Servers", Collections.emptyList());
|
||||||
save = true;
|
save = true;
|
||||||
} if (!config.get().getKeys().contains("Enabled-Creators")) {
|
}
|
||||||
|
if (!config.get().getKeys().contains("Enabled-Creators")) {
|
||||||
config.get().set("Enabled-Creators", Collections.emptyList());
|
config.get().set("Enabled-Creators", Collections.emptyList());
|
||||||
save = true;
|
save = true;
|
||||||
}
|
}
|
||||||
if (save) config.save();
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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()) {
|
for (ConsoleWindow window : sCurrent.values()) {
|
||||||
window.destroy();
|
window.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,11 +372,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(ServerContainer server, String address) {
|
public void connect(ServerContainer server, String address) {
|
||||||
server.setSubData(address);
|
if (server != null) server.setSubData(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(ServerContainer server) {
|
public void disconnect(ServerContainer server) {
|
||||||
server.setSubData(null);
|
if (server != null) server.setSubData(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = Byte.MIN_VALUE)
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
|
|
Loading…
Reference in New Issue