SteamWar/BauSystem
Archiviert
13
0

Add shutdown of bau after five minutes no player #219

Manuell gemergt
YoyoNow hat 11 Commits von BauOnline nach master 2021-04-02 20:49:17 +02:00 zusammengeführt
2 geänderte Dateien mit 37 neuen und 3 gelöschten Zeilen
Nur Änderungen aus Commit efaf18a4f8 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -170,9 +170,7 @@ public class BauSystem extends JavaPlugin implements Listener {
} }
count++; count++;
try { try {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); if (RamUsage.getUsage() > 0.8) {
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
if ((memorySize - freeMemory) / (double) memorySize > 0.8) {
Bukkit.shutdown(); Bukkit.shutdown();
} }
} catch (Throwable throwable) { } catch (Throwable throwable) {

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}
}