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 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) : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -30,10 +30,21 @@ 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(), () -> {
|
||||||
|
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) {
|
switch (minutesAfk) {
|
||||||
case 5:
|
case 5:
|
||||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||||
@ -49,11 +60,18 @@ public class AFKStopperListener implements Listener {
|
|||||||
default:
|
default:
|
||||||
minutesAfk++;
|
minutesAfk++;
|
||||||
}
|
}
|
||||||
|
}, 1);
|
||||||
}, 1200, 1200); //every minute
|
}, 1200, 1200); //every minute
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
if (event.getTo() == null) return;
|
||||||
|
if (event.getFrom().getPitch() != event.getTo().getPitch()) {
|
||||||
minutesAfk = 0;
|
minutesAfk = 0;
|
||||||
}
|
}
|
||||||
|
if (event.getFrom().getYaw() != event.getTo().getYaw()) {
|
||||||
|
minutesAfk = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren