SteamWar/BauSystem
Archiviert
13
0

Add TPS warping to TPSLimit

Dieser Commit ist enthalten in:
jojo 2021-02-08 18:40:43 +01:00
Ursprung 02d509a3ab
Commit a41602bd37
7 geänderte Dateien mit 136 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,34 @@
/*
*
* 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 TPSLimit_15 {
public static void init(LongSupplier longSupplier) {
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
}
}

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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;
@ -55,12 +56,26 @@ 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));
if (TPSUtils.isWarping()) {
sender.sendMessage(BauSystem.PREFIX + "TPS:§e" +
" " + getTps(TPSWatcher.TPSType.ONE_SECOND) +
" " + getTps(TPSWatcher.TPSType.TEN_SECONDS));
} else {
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));
}
return false;
}
private double getTps(TPSWatcher.TPSType tpsType) {
if (TPSUtils.isWarping()) {
return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20));
}
return TPSWatcher.getTPS(tpsType);
}
}

Datei anzeigen

@ -21,7 +21,9 @@ 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.TPSWatcher;
import de.steamwar.core.VersionedRunnable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
@ -77,7 +79,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;
}
@ -104,7 +106,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 +142,7 @@ public class CommandTPSLimiter implements CommandExecutor {
}
public static double getCurrentTPSLimit() {
return currentTPSLimit;
return (double)Math.round(currentTPSLimit * 10.0D) / 10.0D;
}
}

Datei anzeigen

@ -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;
@ -30,6 +31,7 @@ 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> argumentsWarped = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "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) {
@ -37,7 +39,7 @@ public class CommandTPSLimiterTabComplete implements TabCompleter {
return new ArrayList<>();
}
List<String> validArguments = new ArrayList<>(arguments.size());
for (String s : arguments) {
for (String s : TPSUtils.isWarpAllowed() ? argumentsWarped : arguments) {
if (s.startsWith(args[0])) {
validArguments.add(s);
}

Datei anzeigen

@ -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() + getTps() + 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 = getTps();
if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) {
return "§a";
}
@ -104,4 +104,11 @@ public class BauScoreboard implements Listener {
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
}
private double getTps() {
if (TPSUtils.isWarping()) {
return TPSWatcher.getTPS(Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20));
}
return TPSWatcher.getTPS();
}
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
*
* 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.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() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
nanoOffset += nanoDOffset;
}, 1, 1);
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15));
}
public static void setTPS(double tps) {
double d = 50 - (50 / (tps / 20.0));
long nanos = (long) (d * 1000000);
if (nanos < 0) nanos = 0;
if (nanos > 25000000) nanos = 25000000;
nanoDOffset = nanos;
}
public static boolean isWarpAllowed() {
return warp;
}
public static boolean isWarping() {
return nanoDOffset > 0;
}
}