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.ObjectMapValue;
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.InvalidServerException;
import net.ME1312.SubServers.Bungee.SubAPI;
@ -463,12 +464,14 @@ public abstract class Host implements ExtraDataHandler {
*
* @return Success Status
*/
@SuppressWarnings("unchecked")
public boolean destroy() {
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) {
forceRemoveSubServer(server);
for (Map.Entry<String, SubServer> entry : subservers) {
if (entry.getValue().isRunning()) Logger.get("SubServers").info("Stopping " + entry.getValue().getName());
forceRemoveSubServer(entry.getKey());
}
getCreator().terminate();
getCreator().waitFor();

View File

@ -7,12 +7,12 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.PluginDescription;
import java.io.File;
import java.io.IOException;
public final class Plugin extends net.md_5.bungee.api.plugin.Plugin {
private static final PluginDescription description = new PluginDescription();
private final ExceptionRunnable enable;
private final Runnable disable;
private boolean enabled;
@Deprecated
public Plugin() {
@ -43,12 +43,17 @@ public final class Plugin extends net.md_5.bungee.api.plugin.Plugin {
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");
} else try {
enabled = true;
enable.run();
} catch (Throwable e) {
e.printStackTrace();
}
}
public boolean isActive() {
return enabled;
}
@Override
public void onDisable() {
if (disable != null) disable.run();

View File

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

View File

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