Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
8a5c3b1647
Commit
567f88c916
@ -36,31 +36,27 @@ public class AFKStopperListener implements Listener {
|
|||||||
private int minutesAfk = 0;
|
private int minutesAfk = 0;
|
||||||
|
|
||||||
public AFKStopperListener() {
|
public AFKStopperListener() {
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
double load = RamUsage.getLoad();
|
|
||||||
double usage = RamUsage.getUsage();
|
|
||||||
// System.out.println("CPU: " + load + " RAM: " + usage);
|
// System.out.println("CPU: " + load + " RAM: " + usage);
|
||||||
if (load < 50.0 && usage < 0.6) {
|
if (RamUsage.getLoad() < 50.0 && RamUsage.getUsage() < 0.6) {
|
||||||
minutesAfk = 0;
|
minutesAfk = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
switch (minutesAfk) {
|
||||||
switch (minutesAfk) {
|
case 5:
|
||||||
case 5:
|
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
Bukkit.shutdown();
|
||||||
Bukkit.shutdown();
|
return;
|
||||||
return;
|
}
|
||||||
}
|
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));
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 4:
|
||||||
case 4:
|
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
|
||||||
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
|
default:
|
||||||
default:
|
minutesAfk++;
|
||||||
minutesAfk++;
|
}
|
||||||
}
|
|
||||||
}, 1);
|
|
||||||
}, 1200, 1200); //every minute
|
}, 1200, 1200); //every minute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,31 @@ public class RamUsage {
|
|||||||
|
|
||||||
private File meminfo = new File("/proc/meminfo");
|
private File meminfo = new File("/proc/meminfo");
|
||||||
|
|
||||||
|
private double usage = 0D;
|
||||||
|
private double load = 0D;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Thread thread = new Thread(() -> {
|
||||||
|
while (true) {
|
||||||
|
usage = _getUsage();
|
||||||
|
load = _getLoad();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.setName("RamUsage");
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
public static double getUsage() {
|
public static double getUsage() {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double _getUsage() {
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
|
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
|
||||||
String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
|
String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
|
||||||
bufferedReader.readLine();
|
bufferedReader.readLine();
|
||||||
@ -43,6 +67,10 @@ public class RamUsage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double getLoad() {
|
public static double getLoad() {
|
||||||
|
return load;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double _getLoad() {
|
||||||
try {
|
try {
|
||||||
Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start();
|
Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start();
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren