From d80e6d1a069982ff245b1caf1a92f9661b5d7955 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 22 Dec 2020 21:01:29 +0100 Subject: [PATCH] Add 0.5 tps up to 1 --- .../bausystem/commands/CommandTPSLimiter.java | 61 ++++++------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 3453e5a..30d7c30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -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; }