SteamWar/BauSystem
Archiviert
13
0

Add 0.5 tps up to 1

Dieser Commit ist enthalten in:
jojo 2020-12-22 21:01:29 +01:00
Ursprung cc33517e6b
Commit d80e6d1a06

Datei anzeigen

@ -35,7 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
public class CommandTPSLimiter implements CommandExecutor {
private static int currentTPSLimit = 20;
private static double currentTPSLimit = 20;
private static World world = Bukkit.getWorlds().get(0);
private long lastTime = System.nanoTime();
private long currentTime = System.nanoTime();
@ -71,12 +71,14 @@ public class CommandTPSLimiter implements CommandExecutor {
}
try {
int tpsLimitInt = Integer.parseInt(tpsLimit);
if (tpsLimitInt < 1 || tpsLimitInt > 20) {
double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) {
sendInvalidArgumentMessage(player);
return false;
}
currentTPSLimit = tpsLimitInt;
if (tpsLimitDouble <= 1) tpsLimitDouble = (int)(tpsLimitDouble * 10) / 10.0;
else tpsLimitDouble = (int)tpsLimitDouble;
currentTPSLimit = tpsLimitDouble;
sendNewTPSLimitMessage();
tpsLimiter();
} catch (NumberFormatException e) {
@ -91,7 +93,7 @@ public class CommandTPSLimiter implements CommandExecutor {
}
private void sendInvalidArgumentMessage(Player player) {
player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 1 und 20, und 'default' erlaubt.");
player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0.5 und 1 oder 1 und 20, und 'default' erlaubt.");
}
private void tpsLimiter() {
@ -102,13 +104,13 @@ public class CommandTPSLimiter implements CommandExecutor {
} else {
if (tpsLimiter != null) return;
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
sendTntMetaData();
versionDependantCall(() -> TPSLimit_12.sendTntMetaData(world), () -> TPSLimit_15.sendTntMetaData(world));
createVelocityData();
versionDependantCall(() -> TPSLimit_12.createVelocityPacketCache(world), () -> TPSLimit_15.createVelocityPacketCache(world));
for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick();
sendTntData();
sendVelocityData();
versionDependantCall(() -> TPSLimit_12.sendTeleports(world), () -> TPSLimit_15.sendTeleports(world));
versionDependantCall(TPSLimit_12::sendVelocityPackets, TPSLimit_15::sendVelocityPackets);
}
}, 0, 1);
}
@ -133,47 +135,18 @@ public class CommandTPSLimiter implements CommandExecutor {
}
}
private void createVelocityData() {
private void versionDependantCall(Runnable v12, Runnable v15) {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.createVelocityPacketCache(world);
case 12:
v12.run();
break;
default:
TPSLimit_12.createVelocityPacketCache(world);
v15.run();
break;
}
}
private void sendVelocityData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendVelocityPackets();
break;
default:
TPSLimit_12.sendVelocityPackets();
}
}
private void sendTntMetaData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendTntMetaData(world);
break;
default:
TPSLimit_12.sendTntMetaData(world);
}
}
private void sendTntData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendTeleports(world);
break;
default:
TPSLimit_12.sendTeleports(world);
}
}
public static int getCurrentTPSLimit() {
public static double getCurrentTPSLimit() {
return currentTPSLimit;
}