From 987f4f54777cf3da38996e7b6285defb95a0a076 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Sep 2020 15:59:25 +0200 Subject: [PATCH 1/8] Add TPSWatcher --- .../src/de/steamwar/core/Core.java | 6 ++ .../src/de/steamwar/core/TPSWatcher.java | 92 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 893e53a..43e0bf7 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -32,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Core extends JavaPlugin{ private static Core instance; private static final int version; + private static TPSWatcher tpsWatcher; static{ String packageName = Bukkit.getServer().getClass().getPackage().getName(); @@ -52,6 +53,7 @@ public class Core extends JavaPlugin{ @Override public void onLoad() { setInstance(this); + tpsWatcher = new TPSWatcher(); } @Override @@ -75,10 +77,14 @@ public class Core extends JavaPlugin{ public static Core getInstance() { return instance; } + public static int getVersion(){ return version; } + public static TPSWatcher getTpsWatcher() { + return tpsWatcher; + } private static void setInstance(Core instance) { Core.instance = instance; diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java new file mode 100644 index 0000000..75f33eb --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -0,0 +1,92 @@ +/* + 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 . +*/ + +package de.steamwar.core; + +import org.bukkit.Bukkit; + +import java.util.LinkedList; + +public class TPSWatcher { + + private static class TPSMeter { + + private LinkedList meter = new LinkedList<>(); + private int count; + + public TPSMeter(int count) { + this.count = count; + } + + public void add(double tps) { + meter.addLast(tps); + if (meter.size() > count) meter.removeFirst(); + } + + public double get() { + double total = 0; + for (double d : meter) total += d; + return total / meter.size(); + } + + } + + private double now = 20.0; + private TPSMeter one_minute = new TPSMeter(1200); + private TPSMeter five_minutes = new TPSMeter(6000); + private TPSMeter ten_minutes = new TPSMeter(12000); + + private long lastTime = System.currentTimeMillis(); + + private static final double tickTimeDefault = 1000 / 20.0; + private static final double tickDefault = 20.0; + + TPSWatcher() { + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + long tickTime = System.currentTimeMillis() - lastTime; + lastTime = System.currentTimeMillis(); + + if (tickTime != 0) { + now = (tickTimeDefault / tickTime) * tickDefault; + } else { + now = 0; + } + one_minute.add(now); + five_minutes.add(now); + ten_minutes.add(now); + }, 1, 1); + } + + public double getTPS() { + return now; + } + + public double get1TPS() { + return one_minute.get(); + } + + public double get5TPS() { + return five_minutes.get(); + } + + public double get10TPS() { + return ten_minutes.get(); + } + +} -- 2.39.2 From 3959e3c8b867a4c132ca9e3d17a4b011a895d932 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Sep 2020 17:27:00 +0200 Subject: [PATCH 2/8] Optimize TPSWatcher --- .../src/de/steamwar/core/TPSWatcher.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 75f33eb..7e75119 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -21,36 +21,38 @@ package de.steamwar.core; import org.bukkit.Bukkit; +import java.util.Iterator; import java.util.LinkedList; public class TPSWatcher { - private static class TPSMeter { + private LinkedList meter = new LinkedList<>(); + private int count = 30; - private LinkedList meter = new LinkedList<>(); - private int count; + private double sum = 0; + private int sumCount = 0; - public TPSMeter(int count) { - this.count = count; - } - - public void add(double tps) { - meter.addLast(tps); + private void add(double tps) { + sum += tps; + sumCount++; + if (sumCount > 20) { + meter.addLast(sum); if (meter.size() > count) meter.removeFirst(); + sum = 0; + sumCount = 0; } - - public double get() { - double total = 0; - for (double d : meter) total += d; - return total / meter.size(); - } - } - private double now = 20.0; - private TPSMeter one_minute = new TPSMeter(1200); - private TPSMeter five_minutes = new TPSMeter(6000); - private TPSMeter ten_minutes = new TPSMeter(12000); + private double average(int count) { + count = Math.min(count, meter.size()); + if (count == 0) return 20.0; + Iterator doubleIterator = meter.iterator(); + double total = 0; + for (int i = 0; i < count; i++) { + total += doubleIterator.next(); + } + return total / count; + } private long lastTime = System.currentTimeMillis(); @@ -62,31 +64,29 @@ public class TPSWatcher { long tickTime = System.currentTimeMillis() - lastTime; lastTime = System.currentTimeMillis(); + double now = 0; if (tickTime != 0) { now = (tickTimeDefault / tickTime) * tickDefault; - } else { - now = 0; } - one_minute.add(now); - five_minutes.add(now); - ten_minutes.add(now); + add(now); }, 1, 1); } - public double getTPS() { - return now; + public enum TpsAverage { + LAST_SECOND(1), + LAST_TEN_SECONDS(10), + LAST_THIRTY_SECONDS(30); + + private int count; + + TpsAverage(int count) { + this.count = count; + } + } - public double get1TPS() { - return one_minute.get(); - } - - public double get5TPS() { - return five_minutes.get(); - } - - public double get10TPS() { - return ten_minutes.get(); + public double getTPS(TpsAverage average) { + return average(average.count); } } -- 2.39.2 From f83b1359c66936aba8b5457de1f82e3274588714 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Sep 2020 17:28:32 +0200 Subject: [PATCH 3/8] Optimize TPSWatcher --- SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 7e75119..849b838 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -77,7 +77,7 @@ public class TPSWatcher { LAST_TEN_SECONDS(10), LAST_THIRTY_SECONDS(30); - private int count; + private final int count; TpsAverage(int count) { this.count = count; -- 2.39.2 From bb2bf2577efde569130a53547e30caa159c6c2a8 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 4 Oct 2020 18:11:19 +0200 Subject: [PATCH 4/8] Optimize TPSWatcher Remove 30 seconds TPSWatching --- .../src/de/steamwar/core/SpigotTPS_10.java | 13 +++ .../src/de/steamwar/core/SpigotTPS_12.java | 13 +++ .../src/de/steamwar/core/SpigotTPS_14.java | 13 +++ .../src/de/steamwar/core/SpigotTPS_15.java | 13 +++ .../src/de/steamwar/core/SpigotTPS_8.java | 13 +++ .../src/de/steamwar/core/SpigotTPS_9.java | 13 +++ .../src/de/steamwar/core/Core.java | 6 - .../src/de/steamwar/core/TPSWatcher.java | 103 ++++++++++-------- 8 files changed, 137 insertions(+), 50 deletions(-) create mode 100644 SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java create mode 100644 SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java create mode 100644 SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java create mode 100644 SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java create mode 100644 SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java create mode 100644 SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java diff --git a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java new file mode 100644 index 0000000..792022e --- /dev/null +++ b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_10_R1.MinecraftServer; + +public class SpigotTPS_10 { + + private SpigotTPS_10(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java new file mode 100644 index 0000000..60bc6d9 --- /dev/null +++ b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_12_R1.MinecraftServer; + +public class SpigotTPS_12 { + + private SpigotTPS_12(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java new file mode 100644 index 0000000..6bd8491 --- /dev/null +++ b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_14_R1.MinecraftServer; + +public class SpigotTPS_14 { + + private SpigotTPS_14(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java new file mode 100644 index 0000000..e9919f9 --- /dev/null +++ b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_15_R1.MinecraftServer; + +public class SpigotTPS_15 { + + private SpigotTPS_15(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java new file mode 100644 index 0000000..8669728 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_8_R3.MinecraftServer; + +public class SpigotTPS_8 { + + private SpigotTPS_8(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java new file mode 100644 index 0000000..fa5d3e6 --- /dev/null +++ b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java @@ -0,0 +1,13 @@ +package de.steamwar.core; + +import net.minecraft.server.v1_9_R2.MinecraftServer; + +public class SpigotTPS_9 { + + private SpigotTPS_9(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 43e0bf7..5d5ec25 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -32,7 +32,6 @@ import org.bukkit.plugin.java.JavaPlugin; public class Core extends JavaPlugin{ private static Core instance; private static final int version; - private static TPSWatcher tpsWatcher; static{ String packageName = Bukkit.getServer().getClass().getPackage().getName(); @@ -53,7 +52,6 @@ public class Core extends JavaPlugin{ @Override public void onLoad() { setInstance(this); - tpsWatcher = new TPSWatcher(); } @Override @@ -82,10 +80,6 @@ public class Core extends JavaPlugin{ return version; } - public static TPSWatcher getTpsWatcher() { - return tpsWatcher; - } - private static void setInstance(Core instance) { Core.instance = instance; } diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 849b838..97ad502 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -21,45 +21,20 @@ package de.steamwar.core; import org.bukkit.Bukkit; -import java.util.Iterator; -import java.util.LinkedList; - public class TPSWatcher { - private LinkedList meter = new LinkedList<>(); - private int count = 30; + private static final double tickTimeDefault = 1000; + private static final double tickDefault = 20.0; - private double sum = 0; - private int sumCount = 0; - - private void add(double tps) { - sum += tps; - sumCount++; - if (sumCount > 20) { - meter.addLast(sum); - if (meter.size() > count) meter.removeFirst(); - sum = 0; - sumCount = 0; - } - } - - private double average(int count) { - count = Math.min(count, meter.size()); - if (count == 0) return 20.0; - Iterator doubleIterator = meter.iterator(); - double total = 0; - for (int i = 0; i < count; i++) { - total += doubleIterator.next(); - } - return total / count; - } + private static TPSWatcher tps_OneSecond = new TPSWatcher(1000); + private static TPSWatcher tps_TenSecond = new TPSWatcher(10000); private long lastTime = System.currentTimeMillis(); - private static final double tickTimeDefault = 1000 / 20.0; - private static final double tickDefault = 20.0; + private double tps = 20.0; - TPSWatcher() { + private TPSWatcher(long timeInterval) { + timeInterval = timeInterval / 50; Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { long tickTime = System.currentTimeMillis() - lastTime; lastTime = System.currentTimeMillis(); @@ -68,25 +43,65 @@ public class TPSWatcher { if (tickTime != 0) { now = (tickTimeDefault / tickTime) * tickDefault; } - add(now); - }, 1, 1); + if (now < 0) { + now = 0; + } + tps = now; + }, timeInterval, timeInterval); } - public enum TpsAverage { - LAST_SECOND(1), - LAST_TEN_SECONDS(10), - LAST_THIRTY_SECONDS(30); + public enum TPSType { - private final int count; + // With own implementation + ONE_SECOND, + TEN_SECONDS, + // With getting the values from Spigot itself + ONE_MINUTE, + FIVE_MINUTES, + TEN_MINUTES - TpsAverage(int count) { - this.count = count; + } + + public double getTPS() { + return getTPS(TPSType.ONE_SECOND); + } + + public double getTPS(TPSType tpsType) { + switch (tpsType) { + case TEN_SECONDS: + return round(tps_TenSecond.tps); + case ONE_MINUTE: + return round(getSpigotTPS()[0]); + case FIVE_MINUTES: + return round(getSpigotTPS()[1]); + case TEN_MINUTES: + return round(getSpigotTPS()[2]); + + default: + return round(tps_OneSecond.tps); } - } - public double getTPS(TpsAverage average) { - return average(average.count); + private double[] getSpigotTPS() { + switch (Core.getVersion()) { + case 8: + return SpigotTPS_8.getTps(); + case 9: + return SpigotTPS_9.getTps(); + case 10: + return SpigotTPS_10.getTps(); + case 14: + return SpigotTPS_14.getTps(); + case 15: + return SpigotTPS_15.getTps(); + + default: + return SpigotTPS_12.getTps(); + } + } + + private double round(double d) { + return Math.round(d * 10) / 10.0; } } -- 2.39.2 From 599755a52775fd072a2a3dcd155facc9ab4dc11c Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 4 Oct 2020 18:18:55 +0200 Subject: [PATCH 5/8] Fix TPSWatcher for 10 seconds --- SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 97ad502..5c718cc 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -23,7 +23,6 @@ import org.bukkit.Bukkit; public class TPSWatcher { - private static final double tickTimeDefault = 1000; private static final double tickDefault = 20.0; private static TPSWatcher tps_OneSecond = new TPSWatcher(1000); @@ -34,20 +33,19 @@ public class TPSWatcher { private double tps = 20.0; private TPSWatcher(long timeInterval) { - timeInterval = timeInterval / 50; Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { long tickTime = System.currentTimeMillis() - lastTime; lastTime = System.currentTimeMillis(); double now = 0; if (tickTime != 0) { - now = (tickTimeDefault / tickTime) * tickDefault; + now = (timeInterval / (double) tickTime) * tickDefault; } if (now < 0) { now = 0; } tps = now; - }, timeInterval, timeInterval); + }, timeInterval / 50, timeInterval / 50); } public enum TPSType { -- 2.39.2 From 2c76604bb5fd4ec4da822b26118b371bcd48038b Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 12 Oct 2020 12:50:35 +0200 Subject: [PATCH 6/8] Add Copyright Notice --- .../src/de/steamwar/core/SpigotTPS_10.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/SpigotTPS_12.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/SpigotTPS_14.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/SpigotTPS_15.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/SpigotTPS_8.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/SpigotTPS_9.java | 19 +++++++++++++++++++ .../src/de/steamwar/core/Core.java | 1 + .../src/de/steamwar/core/TPSWatcher.java | 9 +++++++-- 8 files changed, 122 insertions(+), 2 deletions(-) diff --git a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java index 792022e..2cc2d26 100644 --- a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java +++ b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_10_R1.MinecraftServer; diff --git a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java index 60bc6d9..17541c7 100644 --- a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java +++ b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_12_R1.MinecraftServer; diff --git a/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java index 6bd8491..d00aba8 100644 --- a/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java +++ b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_14_R1.MinecraftServer; diff --git a/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java index e9919f9..46c1186 100644 --- a/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java +++ b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_15_R1.MinecraftServer; diff --git a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java index 8669728..aeb94d1 100644 --- a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java +++ b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_8_R3.MinecraftServer; diff --git a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java index fa5d3e6..6a0ba28 100644 --- a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java +++ b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java @@ -1,3 +1,22 @@ +/* + 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 . +*/ + package de.steamwar.core; import net.minecraft.server.v1_9_R2.MinecraftServer; diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 5d5ec25..a7e1cab 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -64,6 +64,7 @@ public class Core extends JavaPlugin{ ErrorLogger.init(); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); + TPSWatcher.init(); } diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 5c718cc..a0dd0b9 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -25,8 +25,13 @@ public class TPSWatcher { private static final double tickDefault = 20.0; - private static TPSWatcher tps_OneSecond = new TPSWatcher(1000); - private static TPSWatcher tps_TenSecond = new TPSWatcher(10000); + 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 long lastTime = System.currentTimeMillis(); -- 2.39.2 From 27d1371e7c6579bcc83adf071b5cba53c8f7afae Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 30 Oct 2020 23:14:56 +0100 Subject: [PATCH 7/8] Fix default getTPS() limit on 20 TPS --- .../src/de/steamwar/core/TPSWatcher.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index a0dd0b9..b805393 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -69,6 +69,10 @@ public class TPSWatcher { return getTPS(TPSType.ONE_SECOND); } + public double getTPSUnlimited() { + return getTPS(TPSType.ONE_SECOND); + } + public double getTPS(TPSType tpsType) { switch (tpsType) { case TEN_SECONDS: @@ -85,6 +89,22 @@ public class TPSWatcher { } } + 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() { switch (Core.getVersion()) { case 8: @@ -104,6 +124,10 @@ public class TPSWatcher { } private double round(double d) { + return Math.min(Math.round(d * 10) / 10.0, 20); + } + + private double roundUnlimited(double d) { return Math.round(d * 10) / 10.0; } -- 2.39.2 From b0848d3e78899f3d046a80549b788f2df34479b3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 7 Nov 2020 11:04:54 +0100 Subject: [PATCH 8/8] Fix bugs --- SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index b805393..9b36d29 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -70,7 +70,7 @@ public class TPSWatcher { } public double getTPSUnlimited() { - return getTPS(TPSType.ONE_SECOND); + return getTPSUnlimited(TPSType.ONE_SECOND); } public double getTPS(TPSType tpsType) { @@ -124,7 +124,7 @@ public class TPSWatcher { } private double round(double d) { - return Math.min(Math.round(d * 10) / 10.0, 20); + return Math.max(Math.round(d * 10) / 10.0, 20.0); } private double roundUnlimited(double d) { -- 2.39.2