From 94fd196a08ce5b4054f3e1c5ad7fc9aa51ddc372 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 16:16:25 +0200 Subject: [PATCH 1/8] Add shutdown of bau after one minute no player --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 78869bc..3f889cf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -165,7 +165,7 @@ public class BauSystem extends JavaPlugin implements Listener { Player p = e.getPlayer(); SWScoreboard.removeScoreboard(p); if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) { - Bukkit.shutdown(); + autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } } -- 2.39.5 From c3610be4e112c58b25737c6ad8d25f32a364fb77 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 16:20:34 +0200 Subject: [PATCH 2/8] Add shutdown of bau after one minute no player --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 3f889cf..85d6aed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -165,6 +165,9 @@ public class BauSystem extends JavaPlugin implements Listener { Player p = e.getPlayer(); SWScoreboard.removeScoreboard(p); if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) { + if (autoShutdown != null) { + autoShutdown.cancel(); + } autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } } -- 2.39.5 From 6a62dde0652501cb17963b5718da42966f4a0560 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 18:44:37 +0200 Subject: [PATCH 3/8] Update BauSystem --- .../src/de/steamwar/bausystem/BauSystem.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 85d6aed..dd6e8c9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -43,6 +43,9 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.UUID; import java.util.logging.Level; @@ -168,7 +171,19 @@ public class BauSystem extends JavaPlugin implements Listener { if (autoShutdown != null) { autoShutdown.cancel(); } - autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); + /*autoShutdown = Bukkit.getScheduler().runTaskTimer(this, () -> { + try { + ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "free"); + Process process = processBuilder.start(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + bufferedReader.readLine(); + String s = bufferedReader.readLine(); + } catch (IOException exception) { + Bukkit.shutdown(); + } + }, 1200, 1200);*/ + // (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / Runtime.getRuntime().maxMemory() > 0.8 + autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 6000); } } -- 2.39.5 From 0337c1eb531c48bc730817e1e77714c24108985f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 18:54:46 +0200 Subject: [PATCH 4/8] Add BauSystem shutdown after 5 minutes no player or 80 percentage memory load --- .../src/de/steamwar/bausystem/BauSystem.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index dd6e8c9..571a510 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -46,6 +46,7 @@ import org.bukkit.scheduler.BukkitTask; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; import java.util.UUID; import java.util.logging.Level; @@ -171,19 +172,27 @@ public class BauSystem extends JavaPlugin implements Listener { if (autoShutdown != null) { autoShutdown.cancel(); } - /*autoShutdown = Bukkit.getScheduler().runTaskTimer(this, () -> { - try { - ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "free"); - Process process = processBuilder.start(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - bufferedReader.readLine(); - String s = bufferedReader.readLine(); - } catch (IOException exception) { - Bukkit.shutdown(); + autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() { + int count = 0; + + @Override + public void run() { + if (count >= 5) { + Bukkit.shutdown(); + return; + } + count++; + try { + long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); + long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize(); + if ((memorySize - freeMemory) / (double) memorySize > 0.8) { + Bukkit.shutdown(); + } + } catch (Throwable throwable) { + Bukkit.shutdown(); + } } - }, 1200, 1200);*/ - // (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / Runtime.getRuntime().maxMemory() > 0.8 - autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 6000); + }, 1200, 1200); } } -- 2.39.5 From efaf18a4f8a80f6f6975cf1852ee74ffc1b8e40c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 19:05:02 +0200 Subject: [PATCH 5/8] Add RamUsage to be safe --- .../src/de/steamwar/bausystem/BauSystem.java | 4 +-- .../src/de/steamwar/bausystem/RamUsage.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 3b87d2c..6e3b6a9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -170,9 +170,7 @@ public class BauSystem extends JavaPlugin implements Listener { } count++; try { - long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); - long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize(); - if ((memorySize - freeMemory) / (double) memorySize > 0.8) { + if (RamUsage.getUsage() > 0.8) { Bukkit.shutdown(); } } catch (Throwable throwable) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java new file mode 100644 index 0000000..aa98045 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem; + +import java.lang.management.ManagementFactory; + +public class RamUsage { + + public static double getUsage() { + try { + long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); + long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize(); + return (memorySize - freeMemory) / (double) memorySize; + } catch (Throwable throwable) { + return 1D; + } + } + +} -- 2.39.5 From 85d9c87464e31d64613f85dad3d10a905b379416 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 20:13:57 +0200 Subject: [PATCH 6/8] Add RamUsage to be safe --- BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java index aa98045..9157cbf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java @@ -23,6 +23,10 @@ import java.lang.management.ManagementFactory; public class RamUsage { + private RamUsage() { + throw new IllegalStateException("Utility Class") + } + public static double getUsage() { try { long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); -- 2.39.5 From d706eb9e3a71655bf32f172253d0e2015f0bfded Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 20:14:03 +0200 Subject: [PATCH 7/8] Add RamUsage to be safe --- BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java index 9157cbf..cac2679 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java @@ -24,7 +24,7 @@ import java.lang.management.ManagementFactory; public class RamUsage { private RamUsage() { - throw new IllegalStateException("Utility Class") + throw new IllegalStateException("Utility Class"); } public static double getUsage() { -- 2.39.5 From 9cd68ef1486b2e876a668bcc247b11eb1b49ae8c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 2 Apr 2021 20:43:57 +0200 Subject: [PATCH 8/8] Hotfix BauSystem --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6e3b6a9..945c246 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -164,7 +164,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void run() { - if (count >= 5) { + if (count >= 300) { Bukkit.shutdown(); return; } @@ -177,7 +177,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.shutdown(); } } - }, 1200, 1200); + }, 20, 20); } } -- 2.39.5