SteamWar/SpigotCore
Archiviert
13
0

Fix and simplify YoyoNows solution

Dieser Commit ist enthalten in:
Lixfel 2020-11-07 11:32:38 +01:00
Ursprung 1088e3e037
Commit 6bdb25a3c1
2 geänderte Dateien mit 28 neuen und 62 gelöschten Zeilen

Datei anzeigen

@ -64,8 +64,6 @@ public class Core extends JavaPlugin{
ErrorLogger.init();
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
TPSWatcher.init();
}
@Override

Datei anzeigen

@ -23,57 +23,38 @@ import org.bukkit.Bukkit;
public class TPSWatcher {
private static final double tickDefault = 20.0;
private static final double TICK_DEFAULT = 20.0;
private static TPSWatcher tps_OneSecond;
private static TPSWatcher tps_TenSecond;
public static void init() {
tps_OneSecond = new TPSWatcher(1000);
tps_TenSecond = new TPSWatcher(10000);
}
private static final TPSWatcher tps_OneSecond = new TPSWatcher(1000);
private static final TPSWatcher tps_TenSecond = new TPSWatcher(10000);
private long lastTime = System.currentTimeMillis();
private double tps = 20.0;
private TPSWatcher(long timeInterval) {
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
long tickTime = System.currentTimeMillis() - lastTime;
lastTime = System.currentTimeMillis();
long currentTime = System.currentTimeMillis();
double now = 0;
if (tickTime != 0) {
now = (timeInterval / (double) tickTime) * tickDefault;
}
if (now < 0) {
now = 0;
}
tps = now;
if (currentTime > lastTime)
tps = (timeInterval / (double) (currentTime - lastTime)) * TICK_DEFAULT;
lastTime = currentTime;
}, timeInterval / 50, timeInterval / 50);
}
public enum TPSType {
// With own implementation
ONE_SECOND,
TEN_SECONDS,
// With getting the values from Spigot itself
ONE_MINUTE,
FIVE_MINUTES,
TEN_MINUTES
}
public double getTPS() {
public static double getTPS() {
return getTPS(TPSType.ONE_SECOND);
}
public double getTPSUnlimited() {
public static double getTPSUnlimited() {
return getTPSUnlimited(TPSType.ONE_SECOND);
}
public double getTPS(TPSType tpsType) {
public static double getTPS(TPSType tpsType) {
return Math.min(getTPSUnlimited(tpsType), 20.0);
}
public static double getTPSUnlimited(TPSType tpsType) {
switch (tpsType) {
case TEN_SECONDS:
return round(tps_TenSecond.tps);
@ -83,29 +64,13 @@ public class TPSWatcher {
return round(getSpigotTPS()[1]);
case TEN_MINUTES:
return round(getSpigotTPS()[2]);
case ONE_SECOND:
default:
return round(tps_OneSecond.tps);
}
}
public double getTPSUnlimited(TPSType tpsType) {
switch (tpsType) {
case TEN_SECONDS:
return roundUnlimited(tps_TenSecond.tps);
case ONE_MINUTE:
return roundUnlimited(getSpigotTPS()[0]);
case FIVE_MINUTES:
return roundUnlimited(getSpigotTPS()[1]);
case TEN_MINUTES:
return roundUnlimited(getSpigotTPS()[2]);
default:
return roundUnlimited(tps_OneSecond.tps);
}
}
private double[] getSpigotTPS() {
private static double[] getSpigotTPS() {
switch (Core.getVersion()) {
case 8:
return SpigotTPS_8.getTps();
@ -113,22 +78,25 @@ public class TPSWatcher {
return SpigotTPS_9.getTps();
case 10:
return SpigotTPS_10.getTps();
case 12:
return SpigotTPS_12.getTps();
case 14:
return SpigotTPS_14.getTps();
case 15:
return SpigotTPS_15.getTps();
default:
return SpigotTPS_12.getTps();
return SpigotTPS_15.getTps();
}
}
private double round(double d) {
return Math.max(Math.round(d * 10) / 10.0, 20.0);
}
private double roundUnlimited(double d) {
private static double round(double d) {
return Math.round(d * 10) / 10.0;
}
public enum TPSType {
ONE_SECOND,
TEN_SECONDS,
ONE_MINUTE,
FIVE_MINUTES,
TEN_MINUTES
}
}