Keep the console reader alive during shutdown

This commit is contained in:
ME1312 2021-02-07 03:09:39 -05:00
parent 4e66461848
commit 76e11f0a0d
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 33 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Library.ExtraDataHandler;
import net.ME1312.Galaxi.Library.Map.ObjectMap; import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue; import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException; import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Bungee.SubAPI; import net.ME1312.SubServers.Bungee.SubAPI;
@ -463,12 +464,14 @@ public abstract class Host implements ExtraDataHandler {
* *
* @return Success Status * @return Success Status
*/ */
@SuppressWarnings("unchecked")
public boolean destroy() { public boolean destroy() {
try { try {
String[] subservers = getSubServers().keySet().toArray(new String[0]); Map.Entry<String, SubServer>[] subservers = getSubServers().entrySet().toArray(new Map.Entry[0]);
for (String server : subservers) { for (Map.Entry<String, SubServer> entry : subservers) {
forceRemoveSubServer(server); if (entry.getValue().isRunning()) Logger.get("SubServers").info("Stopping " + entry.getValue().getName());
forceRemoveSubServer(entry.getKey());
} }
getCreator().terminate(); getCreator().terminate();
getCreator().waitFor(); getCreator().waitFor();

View File

@ -7,12 +7,12 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.PluginDescription; import net.md_5.bungee.api.plugin.PluginDescription;
import java.io.File; import java.io.File;
import java.io.IOException;
public final class Plugin extends net.md_5.bungee.api.plugin.Plugin { public final class Plugin extends net.md_5.bungee.api.plugin.Plugin {
private static final PluginDescription description = new PluginDescription(); private static final PluginDescription description = new PluginDescription();
private final ExceptionRunnable enable; private final ExceptionRunnable enable;
private final Runnable disable; private final Runnable disable;
private boolean enabled;
@Deprecated @Deprecated
public Plugin() { public Plugin() {
@ -43,12 +43,17 @@ public final class Plugin extends net.md_5.bungee.api.plugin.Plugin {
if (enable == null) { if (enable == null) {
throw new IllegalStateException("SubServers.Bungee does not run as a plugin, but a wrapper. For more information on how to install, please visit this page: https://github.com/ME1312/SubServers-2/wiki/Install"); throw new IllegalStateException("SubServers.Bungee does not run as a plugin, but a wrapper. For more information on how to install, please visit this page: https://github.com/ME1312/SubServers-2/wiki/Install");
} else try { } else try {
enabled = true;
enable.run(); enable.run();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean isActive() {
return enabled;
}
@Override @Override
public void onDisable() { public void onDisable() {
if (disable != null) disable.run(); if (disable != null) disable.run();

View File

@ -731,6 +731,11 @@ public final class SubProxy extends BungeeCommon implements Listener {
@Override @Override
public void stopListeners() { public void stopListeners() {
if (running) { if (running) {
if (plugin != null && plugin.isActive()) {
shutdown = !super.isRunning;
super.isRunning = true;
}
ListenerInfo[] listeners = getConfig().getListeners().toArray(new ListenerInfo[0]); ListenerInfo[] listeners = getConfig().getListeners().toArray(new ListenerInfo[0]);
super.stopListeners(); super.stopListeners();
@ -742,6 +747,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
} }
} }
private boolean shutdown = false;
protected void shutdown() { protected void shutdown() {
if (running) { if (running) {
legServers.clear(); legServers.clear();
@ -771,6 +777,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
subdata.close(); subdata.close();
Thread.sleep(500); Thread.sleep(500);
} catch (InterruptedException | IOException e) {} } catch (InterruptedException | IOException e) {}
if (shutdown) super.isRunning = false;
} }
} }

View File

@ -291,21 +291,24 @@ public final class ExHost {
} }
} }
@SuppressWarnings("unchecked")
private void stop() { private void stop() {
if (running) { if (running) {
log.info.println("Stopping hosted servers"); log.info.println("Stopping hosted servers");
String[] subservers = servers.keySet().toArray(new String[0]); Map.Entry<String, SubServerImpl>[] subservers = servers.entrySet().toArray(new Map.Entry[0]);
for (String name : subservers) { for (Map.Entry<String, SubServerImpl> entry : subservers) {
SubServerImpl server = servers.get(name); if (entry.getValue().isRunning()) {
server.stop(); log.info.println("Stopping " + entry.getValue().getName());
try { entry.getValue().stop();
server.waitFor(); try {
} catch (Exception e) { entry.getValue().waitFor();
log.error.println(e); } catch (Exception e) {
log.error.println(e);
}
} }
servers.remove(name); servers.remove(entry.getKey());
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort())) UPnP.closePortTCP(server.getPort()); if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(entry.getValue().getPort())) UPnP.closePortTCP(entry.getValue().getPort());
} }
servers.clear(); servers.clear();