getTPS can now be null if the region is not loaded.

This commit is contained in:
Euphyllia Bierque 2024-06-05 02:17:24 +02:00
parent f157317480
commit 0e0e69e0f2
No known key found for this signature in database
GPG Key ID: EF611B23DB2577F1
2 changed files with 21 additions and 24 deletions

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add TPS From Region
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..1da5ee2835ee729b3dfbdc633669cdf304e2eba3 100644
index 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..f85b6efd4d2982acfa173920c9fd601d1ff47cc2 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2397,6 +2397,30 @@ public final class Bukkit {
@@ -2397,6 +2397,28 @@ public final class Bukkit {
}
// Paper end
@ -17,10 +17,9 @@ index 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..1da5ee2835ee729b3dfbdc633669cdf3
+ * Gets the current location TPS.
+ *
+ * @param location the location for which to get the TPS
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server)
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the position is not loaded
+ */
+ @NotNull
+ public double[] getTPS(Location location) {
+ public double @Nullable [] getTPS(Location location) {
+ return server.getTPS(location);
+ }
+
@ -28,10 +27,9 @@ index 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..1da5ee2835ee729b3dfbdc633669cdf3
+ * Gets the current chunk TPS.
+ *
+ * @param chunk the chunk for which to get the TPS
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server)
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the chunk is not loaded
+ */
+ @NotNull
+ public double[] getTPS(Chunk chunk){
+ public double @Nullable [] getTPS(Chunk chunk){
+ return server.getTPS(chunk);
+ }
+ // Folia end
@ -40,10 +38,10 @@ index 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..1da5ee2835ee729b3dfbdc633669cdf3
* Get the advancement specified by this key.
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index d4c5b06fe4be177442ef1abaf1b223c6c2845930..8fb11dea6dbba71970c48af8d308c9cae4426af8 100644
index d4c5b06fe4be177442ef1abaf1b223c6c2845930..4d65b05931dff6420c4da45a3f8ab99f12a31980 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2050,6 +2050,26 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2050,6 +2050,24 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
double getAverageTickTime();
// Paper end
@ -52,19 +50,17 @@ index d4c5b06fe4be177442ef1abaf1b223c6c2845930..8fb11dea6dbba71970c48af8d308c9ca
+ * Gets the current location TPS.
+ *
+ * @param location the location for which to get the TPS
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server)
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the position is not loaded
+ */
+ @NotNull
+ public double[] getTPS(Location location);
+ public double @Nullable [] getTPS(Location location);
+
+ /**
+ * Gets the current chunk TPS.
+ *
+ * @param chunk the chunk for which to get the TPS
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server)
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the chunk is not loaded
+ */
+ @NotNull
+ public double[] getTPS(Chunk chunk);
+ public double @Nullable [] getTPS(Chunk chunk);
+ // Folia end
+
// Paper start

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add TPS From Region
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 273c37b63df3f14488586f9217c7b19a8f3d8ad5..c383fa047c386952e7904b3d645b8f55498e4f25 100644
index 273c37b63df3f14488586f9217c7b19a8f3d8ad5..e9156358bb42cb2e2e43029da1c2fa7e8e00f2f8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3114,6 +3114,41 @@ public final class CraftServer implements Server {
@@ -3114,6 +3114,42 @@ public final class CraftServer implements Server {
};
}
@ -33,15 +33,16 @@ index 273c37b63df3f14488586f9217c7b19a8f3d8ad5..c383fa047c386952e7904b3d645b8f55
+ io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion<io.papermc.paper.threadedregions.TickRegions.TickRegionData, io.papermc.paper.threadedregions.TickRegions.TickRegionSectionData>
+ region = world.regioniser.getRegionAtSynchronised(x, z);
+ if (region == null) {
+ return new double[]{ 20.0, 20.0, 20.0, 20.0, 20.0 };
+ return null;
+ } else {
+ io.papermc.paper.threadedregions.TickRegions.TickRegionData regionData = region.getData();
+ final long currTime = System.nanoTime();
+ return new double[] {
+ regionData.getRegionSchedulingHandle().getTickReport5s(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15s(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport1m(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport5m(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15m(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport5s(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15s(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport1m(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport5m(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15m(currTime).tpsData().segmentAll().average(),
+ };
+ }
+ }