Add shutdown of bau after five minutes no player #219
@ -42,6 +42,10 @@ 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.lang.management.ManagementFactory;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BauSystem extends JavaPlugin implements Listener {
|
||||
@ -153,7 +157,28 @@ 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();
|
||||
if (autoShutdown != null) {
|
||||
autoShutdown.cancel();
|
||||
}
|
||||
autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (count >= 300) {
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
}
|
||||
count++;
|
||||
try {
|
||||
if (RamUsage.getUsage() > 0.8) {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
40
BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java
Normale Datei
40
BauSystem_Main/src/de/steamwar/bausystem/RamUsage.java
Normale Datei
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
private RamUsage() {
|
||||
throw new IllegalStateException("Utility Class");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren