Add TPSUtils #16
@ -27,6 +27,7 @@ import de.steamwar.spectatesystem.listener.PlayerListener;
|
|||||||
import de.steamwar.spectatesystem.listener.CancelListener;
|
import de.steamwar.spectatesystem.listener.CancelListener;
|
||||||
import de.steamwar.spectatesystem.listener.JoinListener;
|
import de.steamwar.spectatesystem.listener.JoinListener;
|
||||||
import de.steamwar.spectatesystem.listener.PlayerSeatListener;
|
import de.steamwar.spectatesystem.listener.PlayerSeatListener;
|
||||||
|
import de.steamwar.spectatesystem.util.TPSUtils;
|
||||||
import de.steamwar.spectatesystem.util.WorldLoader;
|
import de.steamwar.spectatesystem.util.WorldLoader;
|
||||||
import de.steamwar.sql.UserGroup;
|
import de.steamwar.sql.UserGroup;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -59,6 +60,7 @@ public class SpectateSystem extends JavaPlugin {
|
|||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not open ConnectionAcceptor", e);
|
Bukkit.getLogger().log(Level.SEVERE, "Could not open ConnectionAcceptor", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TPSUtils.init();
|
||||||
Bukkit.getPluginCommand("replay").setExecutor(new ReplayCommand());
|
Bukkit.getPluginCommand("replay").setExecutor(new ReplayCommand());
|
||||||
Bukkit.getPluginCommand("inspect").setExecutor(new InspectCommand());
|
Bukkit.getPluginCommand("inspect").setExecutor(new InspectCommand());
|
||||||
Bukkit.getPluginCommand("tpslimit").setExecutor(new TPSLimitCommand());
|
Bukkit.getPluginCommand("tpslimit").setExecutor(new TPSLimitCommand());
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.spectatesystem.commands;
|
package de.steamwar.spectatesystem.commands;
|
||||||
|
|
||||||
import de.steamwar.spectatesystem.SpectateSystem;
|
import de.steamwar.spectatesystem.SpectateSystem;
|
||||||
|
import de.steamwar.spectatesystem.util.TPSUtils;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@ -55,7 +56,7 @@ public class TPSLimitCommand 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 > 40) {
|
||||||
sendInvalidArgumentMessage(player);
|
sendInvalidArgumentMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ public class TPSLimitCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendInvalidArgumentMessage(Player player) {
|
private void sendInvalidArgumentMessage(Player player) {
|
||||||
player.sendMessage("§eSteam§8War» §cNur Zahlen zwischen 0,5 und 20, und 'default' erlaubt.");
|
player.sendMessage("§eSteam§8War» §cNur Zahlen zwischen 0,5 und 40, und 'default' erlaubt.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tpsLimiter() {
|
private void tpsLimiter() {
|
||||||
@ -82,6 +83,7 @@ public class TPSLimitCommand implements CommandExecutor {
|
|||||||
loops = (int) Math.ceil(delay);
|
loops = (int) Math.ceil(delay);
|
||||||
sleepDelay = (long) (50 * delay) / loops;
|
sleepDelay = (long) (50 * delay) / loops;
|
||||||
|
|
||||||
|
TPSUtils.setTPS(currentTPSLimit);
|
||||||
if (currentTPSLimit >= 20) {
|
if (currentTPSLimit >= 20) {
|
||||||
if (tpsLimiter == null) return;
|
if (tpsLimiter == null) return;
|
||||||
tpsLimiter.cancel();
|
tpsLimiter.cancel();
|
||||||
@ -111,4 +113,8 @@ public class TPSLimitCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getCurrentTPSLimit() {
|
||||||
|
return (double) Math.round(currentTPSLimit * 10.0D) / 10.0D;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
38
src/de/steamwar/spectatesystem/util/TPSUtils.java
Normale Datei
38
src/de/steamwar/spectatesystem/util/TPSUtils.java
Normale Datei
@ -0,0 +1,38 @@
|
|||||||
|
package de.steamwar.spectatesystem.util;
|
||||||
|
|
||||||
|
import de.steamwar.core.TPSWatcher;
|
||||||
|
import de.steamwar.spectatesystem.SpectateSystem;
|
||||||
|
import de.steamwar.spectatesystem.commands.TPSLimitCommand;
|
||||||
|
import net.minecraft.server.v1_15_R1.SystemUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class TPSUtils {
|
||||||
|
|
||||||
|
private TPSUtils() {
|
||||||
|
throw new IllegalStateException("Utility Class");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long nanoOffset = 0;
|
||||||
|
private static long nanoDOffset = 0;
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(SpectateSystem.get(), () -> nanoOffset += nanoDOffset, 1, 1);
|
||||||
|
SystemUtils.a = () -> nanoOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 isWarping() {
|
||||||
|
return nanoDOffset > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getTps(TPSWatcher.TPSType tpsType) {
|
||||||
|
if (TPSUtils.isWarping())
|
||||||
|
return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitCommand.getCurrentTPSLimit(), 20));
|
||||||
|
return TPSWatcher.getTPS(tpsType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren