mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
#36 Init SubServers.Console before SubAPI
This commit is contained in:
parent
7158e0a3da
commit
975a12f3b6
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: SubServers-Console
|
||||
main: net.ME1312.SubServers.Console.ConsolePlugin
|
||||
version: 2.13.2a
|
||||
version: 2.13.2b
|
||||
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> 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();
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user