Skip to content

Commit

Permalink
Fix 5-second TPS in /tps command
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnMuijsers committed Mar 22, 2023
1 parent a11f786 commit cbde497
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 11 deletions.
42 changes: 42 additions & 0 deletions patches/api/0008-Specific-interval-TPS-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,48 @@ Subject: [PATCH] Specific interval TPS API
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org

diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index ac9b690fcccb60b587e5345f12f1383afd0a73a1..e9ff914c9e602887c433c3aa7aab5a170dd31f17 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2072,6 +2072,37 @@ public final class Bukkit {
return server.getTPS();
}

+ // Gale start - specific interval TPS API
+
+ /**
+ * Gets the average server TPS over the last 1 minute
+ *
+ * @return the average server TPS over the last 1 minute
+ */
+ public static double get1MinuteTPSAverage() {
+ return server.get1MinuteTPSAverage();
+ }
+
+ /**
+ * Gets the average server TPS over the last 5 minutes
+ *
+ * @return the average server TPS over the last 5 minutes
+ */
+ public static double get5MinuteTPSAverage() {
+ return server.get5MinuteTPSAverage();
+ }
+
+ /**
+ * Gets the average server TPS over the last 15 minutes
+ *
+ * @return the average server TPS over the last 15 minutes
+ */
+ public static double get15MinuteTPSAverage() {
+ return server.get15MinuteTPSAverage();
+ }
+
+ // Gale end - specific interval TPS API
+
/**
* Get a sample of the servers last tick times (in nanos)
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index aec6ef7197ed8caec451954727c1f7149491d3f9..7d0baa4306fecb79d069a7f5aed81e12a80a1f0e 100644
--- a/src/main/java/org/bukkit/Server.java
Expand Down
51 changes: 49 additions & 2 deletions patches/api/0009-5-second-TPS-average.patch
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,59 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index e9ff914c9e602887c433c3aa7aab5a170dd31f17..daf11e58b0a5f8cc8890af24fa51e3c46a4043b6 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2072,8 +2072,30 @@ public final class Bukkit {
return server.getTPS();
}

+ // Gale start - Purpur - 5 second TPS average
+ /**
+ * Gets the current server TPS
+ * @return current server TPS (5s, 1m, 5m, 15m in Gale-Server)
+ */
+ @NotNull
+ public static double[] getTPSIncluding5SecondAverage() {
+ return server.getTPSIncluding5SecondAverage();
+ }
+ // Gale end - Purpur - 5 second TPS average
+
// Gale start - specific interval TPS API

+ // Gale start - Purpur - 5 second TPS average
+ /**
+ * Gets the average server TPS over the last 5 seconds
+ *
+ * @return the average server TPS over the last 5 seconds
+ */
+ public static double get5SecondTPSAverage() {
+ return server.get5SecondTPSAverage();
+ }
+ // Gale end - Purpur - 5 second TPS average
+
/**
* Gets the average server TPS over the last 1 minute
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 7d0baa4306fecb79d069a7f5aed81e12a80a1f0e..bf387ffaca8e245af1b06adcb73b8a118aeb0263 100644
index 7d0baa4306fecb79d069a7f5aed81e12a80a1f0e..359ec91be83f52776cb1da092fd1756085816668 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1753,6 +1753,15 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -1751,8 +1751,27 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@NotNull
public double[] getTPS();

+ // Gale start - Purpur - 5 second TPS average
+ /**
+ * Gets the current server TPS
+ *
+ * @return current server TPS (5s, 1m, 5m, 15m in Gale-Server)
+ */
+ @NotNull
+ double[] getTPSIncluding5SecondAverage();
+ // Gale end - Purpur - 5 second TPS average
+
// Gale start - specific interval TPS API

+ // Gale start - Purpur - 5 second TPS average
Expand Down
4 changes: 2 additions & 2 deletions patches/api/0010-Last-tick-time-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index bf387ffaca8e245af1b06adcb73b8a118aeb0263..4c519dbd706cac728f31a7ccd99cc1e165812599 100644
index 359ec91be83f52776cb1da092fd1756085816668..db76574dd624e7edabc0fde717e7788dd66b7845 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2182,4 +2182,30 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2192,4 +2192,30 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull org.bukkit.potion.PotionBrewer getPotionBrewer();
// Paper end
Expand Down
31 changes: 26 additions & 5 deletions patches/server/0133-5-second-TPS-average.patch
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ index fa56cd09102a89692b42f1d14257990508c5c720..fac07dda413002c12276131efbe4ee38
setListData(vector);
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9f9e2e03ad62649e69a1dc628966b73802665c49..c727b4fa39a7598c23ccc05add204e1b3a001436 100644
index 7e4cb5c0c8cf9e75a709f18d170fc2ff658d9357..bfaab8a9bdde515db9694b7b504fe272835b5f14 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1036,6 +1036,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Expand All @@ -79,11 +79,25 @@ index 9f9e2e03ad62649e69a1dc628966b73802665c49..c727b4fa39a7598c23ccc05add204e1b
tps5.add(currentTps, diff);
tps15.add(currentTps, diff);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index ffd6decc34a5fc30893a958f7ab6bd0273fba1a8..899d37d717de53ce49ebe8fb808633398eee19d3 100644
index ffd6decc34a5fc30893a958f7ab6bd0273fba1a8..d7eb2077192b028c901d7a7d7bd3a9ea6c28c529 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2715,6 +2715,13 @@ public final class CraftServer implements Server {
@@ -2713,8 +2713,27 @@ public final class CraftServer implements Server {
};
}

+ // Gale start - Purpur - 5 second TPS average
+ @Override
+ public double[] getTPSIncluding5SecondAverage() {
+ return new double[] {
+ net.minecraft.server.MinecraftServer.getServer().tps5s.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps1.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps5.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps15.getAverage()
+ };
+ }
+ // Gale end - Purpur - 5 second TPS average
+
// Gale start - specific interval TPS API

+ // Gale start - Purpur - 5 second TPS average
Expand All @@ -97,10 +111,17 @@ index ffd6decc34a5fc30893a958f7ab6bd0273fba1a8..899d37d717de53ce49ebe8fb80863339
public double get1MinuteTPSAverage() {
return net.minecraft.server.MinecraftServer.getServer().tps1.getAverage();
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
index 9bede6a26c08ede063c7a38f1149c811df14b258..29e27dd3c8908956f2708a3562e69e4f35b26249 100644
index 9bede6a26c08ede063c7a38f1149c811df14b258..98479976ca48cf7e84789ee79faab50d0ef6ba6d 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -31,7 +31,7 @@ public class TicksPerSecondCommand extends Command
@@ -25,13 +25,13 @@ public class TicksPerSecondCommand extends Command
}

// Paper start - Further improve tick handling
- double[] tps = org.bukkit.Bukkit.getTPS();
+ double[] tps = org.bukkit.Bukkit.getTPSIncluding5SecondAverage(); // Gale - Purpur - 5 second TPS average
String[] tpsAvg = new String[tps.length];

for ( int i = 0; i < tps.length; i++) {
tpsAvg[i] = TicksPerSecondCommand.format( tps[i] );
}
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0135-Last-tick-time-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 899d37d717de53ce49ebe8fb808633398eee19d3..d278472bf407ae7c678bccb3a061437a5642749e 100644
index d7eb2077192b028c901d7a7d7bd3a9ea6c28c529..716867461631119de283e750cf14820b5630ccd5 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2962,4 +2962,22 @@ public final class CraftServer implements Server {
@@ -2974,4 +2974,22 @@ public final class CraftServer implements Server {
}

// Paper end
Expand Down

0 comments on commit cbde497

Please sign in to comment.