Fix 30 Minute shutdown for empty server
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
e2779ba107
Commit
c6a045fe94
@ -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;
|
Bukkit.shutdown();
|
||||||
} else if (Bukkit.getOnlinePlayers().isEmpty()) {
|
return;
|
||||||
Bukkit.shutdown();
|
}
|
||||||
|
} else if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) {
|
||||||
|
afkTicks = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (minutesAfk) {
|
switch (afkTicks) {
|
||||||
case 30:
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren