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