From f16601ea0fb99b8b0f11d1543877ea33f79e4b8e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 16 Dec 2019 09:55:01 +0100 Subject: [PATCH] Adding shutdown hooks --- .../steamwar/bungeecore/SubserverSystem.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 1478192..4900383 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -30,12 +30,19 @@ public class SubserverSystem { public static Subserver startArena(ArenaMode modus, String map){ int port = freePort(2500); String serverName = modus.getDisplayName() + (port - 2500); - return new Subserver(Servertype.ARENA, serverName, port, - MC_SCRIPT, "-a", modus.getInternalName(), serverName, Integer.toString(port), map, "0", modus.serverJar()); + + return new Subserver(Servertype.ARENA, serverName, port, () -> { + try { + new ProcessBuilder("rm", "-r", "~/backbone/arenaserver/" + serverName).start(); + } catch (IOException e) { + throw new SecurityException("Could not clean up folder", e); + } + }, MC_SCRIPT, "-a", modus.getInternalName(), serverName, Integer.toString(port), map, "0", modus.serverJar()); } public static Subserver startEventArena(EventFight eventFight, String serverName){ int port = freePort(2500); + return new Subserver(Servertype.ARENA, serverName, port, MC_SCRIPT, "-a", eventFight.getSpielmodus().getInternalName(), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(EventCommand.TIME_FORMAT), Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID()), eventFight.getSpielmodus().serverJar()); } @@ -43,8 +50,13 @@ public class SubserverSystem { public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){ int port = freePort(4000); - new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port, - MC_SCRIPT, "-a", m.getInternalName(), p.getName(), Integer.toString(port), map, "-1", m.serverJar()).sendPlayer(p); + new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port, () -> { + try { + new ProcessBuilder("rm", "-r", "~/backbone/arenaserver/" + p.getName()).start(); + } catch (IOException e) { + throw new SecurityException("Could not clean up folder", e); + } + }, MC_SCRIPT, "-a", m.getInternalName(), p.getName(), Integer.toString(port), map, "-1", m.serverJar()).sendPlayer(p); } public static void sendToBauServer(ProxiedPlayer p, UUID owner){