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