Add unlimited TPS and better AFKStopperListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
e01d551a21
Commit
8a5c3b1647
@ -31,20 +31,28 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Linked
|
||||
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() {
|
||||
super("tpslimit");
|
||||
tabCompletions.add("0,5");
|
||||
for (int i = 0; i <= 20; i++) {
|
||||
tabCompletions.add(i + "");
|
||||
}
|
||||
if (TPSWarpUtils.isWarpAllowed()) {
|
||||
for (int i = 20; i <= 60; i += 5) {
|
||||
tabCompletions.add(i + "");
|
||||
}
|
||||
for (int i = 60; i <= 240; i += 10) {
|
||||
tabCompletions.add(i + "");
|
||||
}
|
||||
}
|
||||
if (FreezeUtils.freezeEnabled) {
|
||||
tabCompletions.add("0");
|
||||
@ -79,7 +87,7 @@ public class TPSLimitCommand extends SWCommand implements Enable {
|
||||
sendNewTPSLimitMessage(true);
|
||||
return;
|
||||
}
|
||||
if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) {
|
||||
if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? MAX_TPS : 20)) {
|
||||
sendInvalidArgumentMessage(p);
|
||||
return;
|
||||
}
|
||||
@ -121,6 +129,6 @@ public class TPSLimitCommand extends SWCommand implements Enable {
|
||||
}
|
||||
|
||||
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) : "");
|
||||
}
|
||||
}
|
@ -32,6 +32,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static de.steamwar.bausystem.features.tpslimit.TPSLimitCommand.MAX_TPS;
|
||||
|
||||
@UtilityClass
|
||||
public class TPSLimitUtils {
|
||||
|
||||
@ -88,7 +90,7 @@ public class TPSLimitUtils {
|
||||
@SuppressWarnings("unused")
|
||||
public static void setTPS(double d) {
|
||||
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;
|
||||
tpsLimiter();
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ public class TPSWarpUtils {
|
||||
|
||||
public static void setTPS(double tps) {
|
||||
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 (bukkitTask == null) return;
|
||||
bukkitTask.cancel();
|
||||
|
@ -30,10 +30,21 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@Linked
|
||||
public class AFKStopperListener implements Listener {
|
||||
|
||||
// CPU > 50%
|
||||
// RAM > 60%
|
||||
|
||||
private int minutesAfk = 0;
|
||||
|
||||
public AFKStopperListener() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getInstance(), () -> {
|
||||
double load = RamUsage.getLoad();
|
||||
double usage = RamUsage.getUsage();
|
||||
// System.out.println("CPU: " + load + " RAM: " + usage);
|
||||
if (load < 50.0 && usage < 0.6) {
|
||||
minutesAfk = 0;
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
switch (minutesAfk) {
|
||||
case 5:
|
||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
@ -49,11 +60,18 @@ public class AFKStopperListener implements Listener {
|
||||
default:
|
||||
minutesAfk++;
|
||||
}
|
||||
}, 1);
|
||||
}, 1200, 1200); //every minute
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.getTo() == null) return;
|
||||
if (event.getFrom().getPitch() != event.getTo().getPitch()) {
|
||||
minutesAfk = 0;
|
||||
}
|
||||
if (event.getFrom().getYaw() != event.getTo().getYaw()) {
|
||||
minutesAfk = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren