SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'Add TPS warping to TPSLimit' (#192) from TPSWarp into master

Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2021-02-12 11:08:58 +01:00
Commit 48346b1bc2
9 geänderte Dateien mit 127 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -28,9 +28,7 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
class TPSLimit_12 { class TPSLimit_12 {

Datei anzeigen

@ -29,7 +29,6 @@ import org.bukkit.entity.TNTPrimed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
class TPSLimit_15 { class TPSLimit_15 {

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -106,6 +106,7 @@ public class BauSystem extends JavaPlugin implements Listener {
new AFKStopper(); new AFKStopper();
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
TPSUtils.init();
} }
public static BauSystem getPlugin() { public static BauSystem getPlugin() {

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.TPSUtils;
import de.steamwar.core.TPSWatcher; import de.steamwar.core.TPSWatcher;
import de.steamwar.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
@ -31,6 +32,8 @@ import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
import static de.steamwar.bausystem.world.TPSUtils.getTps;
public class CommandInfo implements CommandExecutor { public class CommandInfo implements CommandExecutor {
@Override @Override
@ -55,12 +58,17 @@ public class CommandInfo implements CommandExecutor {
} }
sender.sendMessage(membermessage.toString()); sender.sendMessage(membermessage.toString());
sender.sendMessage(BauSystem.PREFIX + "TPS:§e" + StringBuilder tpsMessage = new StringBuilder();
" " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND) + tpsMessage.append(BauSystem.PREFIX).append("TPS:§e");
" " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS) + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND));
" " + TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE) + tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS));
" " + TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES) + if (!TPSUtils.isWarping()) {
" " + TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES)); 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; return false;
} }
} }

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.TPSUtils;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.steamwar.core.VersionedRunnable; import de.steamwar.core.VersionedRunnable;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
@ -77,7 +78,7 @@ public class CommandTPSLimiter implements CommandExecutor {
try { try {
double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.')); double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) { if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) {
sendInvalidArgumentMessage(player); sendInvalidArgumentMessage(player);
return false; return false;
} }
@ -96,7 +97,7 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
private void sendInvalidArgumentMessage(Player player) { 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() { private void tpsLimiter() {
@ -104,7 +105,8 @@ public class CommandTPSLimiter implements CommandExecutor {
loops = (int)Math.ceil(delay); loops = (int)Math.ceil(delay);
sleepDelay = (long) (50 * delay) / loops; sleepDelay = (long) (50 * delay) / loops;
if (currentTPSLimit == 20) { TPSUtils.setTPS(currentTPSLimit);
if (currentTPSLimit >= 20) {
if (tpsLimiter == null) return; if (tpsLimiter == null) return;
tpsLimiter.cancel(); tpsLimiter.cancel();
tpsLimiter = null; tpsLimiter = null;
@ -139,7 +141,7 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
public static double getCurrentTPSLimit() { 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; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.world.TPSUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
@ -29,7 +30,11 @@ import java.util.List;
public class CommandTPSLimiterTabComplete implements TabCompleter { 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"));
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 @Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

Datei anzeigen

@ -73,7 +73,7 @@ public class BauScoreboard implements Listener {
} }
strings.add("§4"); 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(); int i = strings.size();
HashMap<String, Integer> result = new HashMap<>(); HashMap<String, Integer> result = new HashMap<>();
@ -87,7 +87,7 @@ public class BauScoreboard implements Listener {
} }
private String tpsColor() { private String tpsColor() {
double tps = TPSWatcher.getTPS(); double tps = TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND);
if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) {
return "§a"; return "§a";
} }

Datei anzeigen

@ -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),
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);
}
}