Add TPS warping to TPSLimit #192
@ -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 {
|
||||
|
||||
|
@ -29,7 +29,6 @@ import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
class TPSLimit_15 {
|
||||
|
||||
|
33
BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java
Normale Datei
33
BauSystem_15/src/de/steamwar/bausystem/world/TPSUtils_15.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String> 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<String> 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"));
|
||||
|
||||
Chaoscaot
hat
Hier noch eine Leerzeile hin Hier noch eine Leerzeile hin
|
||||
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<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
@ -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<String, Integer> 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";
|
||||
}
|
||||
|
65
BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java
Normale Datei
65
BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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),
|
||||
Chaoscaot
hat
Der Task wird nicht gebraucht, wenn der Server auf der 1.12 Läuft. Der Task wird nicht gebraucht, wenn der Server auf der 1.12 Läuft.
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren
Unused Import