diff --git a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java index b2ebadc..4cd4c22 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java @@ -28,9 +28,7 @@ import org.bukkit.entity.FallingBlock; import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; class TPSLimit_12 { diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java index a1621dc..2860e2a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java @@ -29,7 +29,6 @@ import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; import java.util.List; -import java.util.Set; class TPSLimit_15 { diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java new file mode 100644 index 0000000..4cfeaac --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java @@ -0,0 +1,33 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world; + +import net.minecraft.server.v1_15_R1.SystemUtils; + +import java.util.function.LongSupplier; + +public class TPSUtils_15 { + + public static void init(LongSupplier longSupplier) { + SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 96bde54..01d66dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -106,6 +106,7 @@ public class BauSystem extends JavaPlugin implements Listener { new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); + TPSUtils.init(); } public static BauSystem getPlugin() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 980133b..6043e74 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.TPSUtils; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; @@ -31,6 +32,8 @@ import org.bukkit.entity.Player; import java.util.List; +import static de.steamwar.bausystem.world.TPSUtils.getTps; + public class CommandInfo implements CommandExecutor { @Override @@ -55,12 +58,17 @@ public class CommandInfo implements CommandExecutor { } sender.sendMessage(membermessage.toString()); - sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES) + - " " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); + StringBuilder tpsMessage = new StringBuilder(); + tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); + if (!TPSUtils.isWarping()) { + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE)); + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES)); + tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); + } + sender.sendMessage(tpsMessage.toString()); return false; } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 7a749c7..f997911 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.TPSUtils; import de.steamwar.bausystem.world.Welt; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; @@ -77,7 +78,7 @@ public class CommandTPSLimiter implements CommandExecutor { try { double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.')); - if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) { + if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) { sendInvalidArgumentMessage(player); return false; } @@ -96,7 +97,7 @@ public class CommandTPSLimiter implements CommandExecutor { } private void sendInvalidArgumentMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und 20, und 'default' erlaubt."); + player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und " + (TPSUtils.isWarpAllowed() ? 40 : 20) + ", und 'default' erlaubt."); } private void tpsLimiter() { @@ -104,7 +105,8 @@ public class CommandTPSLimiter implements CommandExecutor { loops = (int)Math.ceil(delay); sleepDelay = (long) (50 * delay) / loops; - if (currentTPSLimit == 20) { + TPSUtils.setTPS(currentTPSLimit); + if (currentTPSLimit >= 20) { if (tpsLimiter == null) return; tpsLimiter.cancel(); tpsLimiter = null; @@ -139,7 +141,7 @@ public class CommandTPSLimiter implements CommandExecutor { } public static double getCurrentTPSLimit() { - return currentTPSLimit; + return (double)Math.round(currentTPSLimit * 10.0D) / 10.0D; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index 9b401ee..00dc116 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.TPSUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -29,7 +30,11 @@ import java.util.List; public class CommandTPSLimiterTabComplete implements TabCompleter { - private List arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); + private List arguments = new ArrayList<>(Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")); + + public CommandTPSLimiterTabComplete() { + if (TPSUtils.isWarpAllowed()) arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40")); + } @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 17873b7..0a93414 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -73,7 +73,7 @@ public class BauScoreboard implements Listener { } strings.add("§4"); - strings.add("§eTPS§8: " + tpsColor() + TPSWatcher.getTPS() + tpsLimit()); + strings.add("§eTPS§8: " + tpsColor() + TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); int i = strings.size(); HashMap result = new HashMap<>(); @@ -87,7 +87,7 @@ public class BauScoreboard implements Listener { } private String tpsColor() { - double tps = TPSWatcher.getTPS(); + double tps = TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { return "§a"; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java new file mode 100644 index 0000000..563e01a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -0,0 +1,65 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.CommandTPSLimiter; +import de.steamwar.core.TPSWatcher; +import de.steamwar.core.VersionedRunnable; +import org.bukkit.Bukkit; + +public class TPSUtils { + + private TPSUtils() { + throw new IllegalStateException("Utility Class"); + } + + private static boolean warp = true; + private static long nanoOffset = 0; + private static long nanoDOffset = 0; + + public static void init() { + VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), + new VersionedRunnable(() -> { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); + TPSUtils_15.init(() -> nanoOffset); + }, 15)); + } + + public static void setTPS(double tps) { + double d = 50 - (50 / (tps / 20.0)); + nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 25000000)); + } + + public static boolean isWarpAllowed() { + return warp; + } + + public static boolean isWarping() { + return nanoDOffset > 0; + } + + public static double getTps(TPSWatcher.TPSType tpsType) { + if (TPSUtils.isWarping()) return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20)); + return TPSWatcher.getTPS(tpsType); + } + +}