From 24524036a8a78f0717eaa007ce72707ea7c323b4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 20 Feb 2023 12:15:03 +0100 Subject: [PATCH] Add Initial setup --- src/de/steamwar/bungeecore/Storage.java | 6 ++++++ src/de/steamwar/bungeecore/Subserver.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/de/steamwar/bungeecore/Storage.java b/src/de/steamwar/bungeecore/Storage.java index fdcc581..0cec8d8 100644 --- a/src/de/steamwar/bungeecore/Storage.java +++ b/src/de/steamwar/bungeecore/Storage.java @@ -48,4 +48,10 @@ public class Storage { public static final Map teamServers = new HashMap<>(); // TeamID -> ServerInfo map public static final Map> directTabItems = new HashMap<>(); + + public static final Map serverToNodeMap = new HashMap<>(); + + public static final Map> nodeToServerMap = new HashMap<>(); + + public static final Map timeOfServerEmpty = new HashMap<>(); } diff --git a/src/de/steamwar/bungeecore/Subserver.java b/src/de/steamwar/bungeecore/Subserver.java index c916f82..a49abde 100644 --- a/src/de/steamwar/bungeecore/Subserver.java +++ b/src/de/steamwar/bungeecore/Subserver.java @@ -140,6 +140,7 @@ public class Subserver implements Runnable { if(!process.waitFor(1, TimeUnit.MINUTES)) process.destroyForcibly(); thread.join(); + cleanup(); }catch(InterruptedException e){ logger.log(Level.SEVERE, "Subserver stop interrupted!", e); Thread.currentThread().interrupt(); @@ -152,12 +153,24 @@ public class Subserver implements Runnable { process.destroy(); } thread.join(); + cleanup(); }catch(InterruptedException e){ logger.log(Level.SEVERE, "Subserver stop interrupted!", e); Thread.currentThread().interrupt(); } } + private void cleanup() { + String nodeName = Storage.serverToNodeMap.remove(this); + if (nodeName != null) { + Storage.nodeToServerMap.computeIfPresent(nodeName, (s, list) -> { + list.remove(this); + if (list.isEmpty()) return null; + return list; + }); + } + } + static void shutdown(){ while (!serverList.isEmpty()) { Subserver server = serverList.get(0); @@ -240,4 +253,8 @@ public class Subserver implements Runnable { shutdownCallback.run(); } } + + public long getPID() { + return process.pid(); + } }