SteamWar/BauSystem2.0
Archiviert
12
0

Fix 30 Minute shutdown for empty server
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2023-09-08 08:55:03 +02:00
Ursprung e2779ba107
Commit c6a045fe94

Datei anzeigen

@ -34,42 +34,44 @@ public class AFKStopperListener implements Listener {
// CPU > 50% // CPU > 50%
// RAM > 60% // RAM > 60%
private int minutesAfk = 0; private int afkTicks = 0;
public AFKStopperListener() { public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
// System.out.println("CPU: " + load + " RAM: " + usage); // System.out.println("CPU: " + load + " RAM: " + usage);
if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) { if (Bukkit.getOnlinePlayers().isEmpty()) {
minutesAfk = 0; if (RamUsage.getLoad() >= 50.0 || RamUsage.getUsage() >= 0.6) {
return;
} else if (Bukkit.getOnlinePlayers().isEmpty()) {
Bukkit.shutdown(); Bukkit.shutdown();
return; return;
} }
switch (minutesAfk) { } else if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) {
case 30: afkTicks = 0;
return;
}
switch (afkTicks) {
case 90:
Bukkit.shutdown(); Bukkit.shutdown();
break; break;
case 5: case 15:
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p)); p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
} }
case 4: case 12:
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE"); BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
default: default:
minutesAfk++; afkTicks++;
} }
}, 1200, 1200); //every minute }, 20*60, 20*60); //every minute
} }
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (event.getTo() == null) return; if (event.getTo() == null) return;
if (event.getFrom().getPitch() != event.getTo().getPitch()) { if (event.getFrom().getPitch() != event.getTo().getPitch()) {
minutesAfk = 0; afkTicks = 0;
} }
if (event.getFrom().getYaw() != event.getTo().getYaw()) { if (event.getFrom().getYaw() != event.getTo().getYaw()) {
minutesAfk = 0; afkTicks = 0;
} }
} }