SteamWar/BauSystem2.0
Archiviert
12
0

Add unlimited TPS and better AFKStopperListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-06-15 22:49:38 +02:00
Ursprung e01d551a21
Commit 8a5c3b1647
4 geänderte Dateien mit 51 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -31,20 +31,28 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Linked @Linked
public class TPSLimitCommand extends SWCommand implements Enable { public class TPSLimitCommand extends SWCommand implements Enable {
private final List<String> tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); private final List<String> tabCompletions = new ArrayList<>();
static final int MAX_TPS = Integer.MAX_VALUE;
public TPSLimitCommand() { public TPSLimitCommand() {
super("tpslimit"); super("tpslimit");
tabCompletions.add("0,5");
for (int i = 0; i <= 20; i++) {
tabCompletions.add(i + "");
}
if (TPSWarpUtils.isWarpAllowed()) { if (TPSWarpUtils.isWarpAllowed()) {
for (int i = 20; i <= 60; i += 5) { for (int i = 20; i <= 60; i += 5) {
tabCompletions.add(i + ""); tabCompletions.add(i + "");
} }
for (int i = 60; i <= 240; i += 10) {
tabCompletions.add(i + "");
}
} }
if (FreezeUtils.freezeEnabled) { if (FreezeUtils.freezeEnabled) {
tabCompletions.add("0"); tabCompletions.add("0");
@ -79,7 +87,7 @@ public class TPSLimitCommand extends SWCommand implements Enable {
sendNewTPSLimitMessage(true); sendNewTPSLimitMessage(true);
return; return;
} }
if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) { if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) {
sendInvalidArgumentMessage(p); sendInvalidArgumentMessage(p);
return; return;
} }
@ -121,6 +129,6 @@ public class TPSLimitCommand extends SWCommand implements Enable {
} }
private void sendInvalidArgumentMessage(Player player) { private void sendInvalidArgumentMessage(Player player) {
BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? 60 : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : ""); BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : "");
} }
} }

Datei anzeigen

@ -32,6 +32,8 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import static de.steamwar.bausystem.features.tpslimit.TPSLimitCommand.MAX_TPS;
@UtilityClass @UtilityClass
public class TPSLimitUtils { public class TPSLimitUtils {
@ -88,7 +90,7 @@ public class TPSLimitUtils {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setTPS(double d) { public static void setTPS(double d) {
if (d < 0.5) d = 0.5; if (d < 0.5) d = 0.5;
if (d > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) d = (TPSWarpUtils.isWarpAllowed() ? 60 : 20); if (d > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) d = (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20);
currentTPSLimit = d; currentTPSLimit = d;
tpsLimiter(); tpsLimiter();
} }

Datei anzeigen

@ -40,7 +40,8 @@ public class TPSWarpUtils {
public static void setTPS(double tps) { public static void setTPS(double tps) {
double d = 50 - (50 / (tps / 20.0)); double d = 50 - (50 / (tps / 20.0));
nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); // nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000));
nanoDOffset = (long) (d * 1000000);
if (nanoDOffset == 0) { if (nanoDOffset == 0) {
if (bukkitTask == null) return; if (bukkitTask == null) return;
bukkitTask.cancel(); bukkitTask.cancel();

Datei anzeigen

@ -30,30 +30,48 @@ import org.bukkit.event.player.PlayerMoveEvent;
@Linked @Linked
public class AFKStopperListener implements Listener { public class AFKStopperListener implements Listener {
// CPU > 50%
// RAM > 60%
private int minutesAfk = 0; private int minutesAfk = 0;
public AFKStopperListener() { public AFKStopperListener() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> {
switch (minutesAfk) { double load = RamUsage.getLoad();
case 5: double usage = RamUsage.getUsage();
if (Bukkit.getOnlinePlayers().isEmpty()) { // System.out.println("CPU: " + load + " RAM: " + usage);
Bukkit.shutdown(); if (load < 50.0 && usage < 0.6) {
return; minutesAfk = 0;
} return;
for (Player p : Bukkit.getOnlinePlayers()) {
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
}
break;
case 4:
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
default:
minutesAfk++;
} }
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
switch (minutesAfk) {
case 5:
if (Bukkit.getOnlinePlayers().isEmpty()) {
Bukkit.shutdown();
return;
}
for (Player p : Bukkit.getOnlinePlayers()) {
p.kickPlayer(BauSystem.MESSAGE.parse("AFK_KICK_MESSAGE", p));
}
break;
case 4:
BauSystem.MESSAGE.broadcast("AFK_WARNING_MESSAGE");
default:
minutesAfk++;
}
}, 1);
}, 1200, 1200); //every minute }, 1200, 1200); //every minute
} }
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
minutesAfk = 0; if (event.getTo() == null) return;
if (event.getFrom().getPitch() != event.getTo().getPitch()) {
minutesAfk = 0;
}
if (event.getFrom().getYaw() != event.getTo().getYaw()) {
minutesAfk = 0;
}
} }
} }