Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions folia-api/paper-patches/features/0004-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 14d81c7b138ebf999d5812d26fbf869209c100f3..b9d34c0b80a5d0c26f43e4959c3a8256a854585a 100644
index 14d81c7b138ebf999d5812d26fbf869209c100f3..a363d94bfe4b79bd45732670e67406c0a8e86ca1 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2987,6 +2987,42 @@ public final class Bukkit {
@@ -2987,6 +2987,77 @@ public final class Bukkit {
return server.isGlobalTickThread();
}
// Paper end - Folia region threading API
Expand Down Expand Up @@ -47,15 +47,50 @@ index 14d81c7b138ebf999d5812d26fbf869209c100f3..b9d34c0b80a5d0c26f43e4959c3a8256
+ public static double @Nullable [] getRegionTPS(@NotNull World world, int chunkX, int chunkZ) {
+ return server.getRegionTPS(world, chunkX, chunkZ);
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified location, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param location The location for which to get the TPS
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ public static double @Nullable [] getRegionAverageTickTimes(@NotNull Location location) {
+ return server.getRegionAverageTickTimes(location);
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param chunk - The specified chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ public static double @Nullable [] getRegionAverageTickTimes(@NotNull Chunk chunk) {
+ return server.getRegionAverageTickTimes(chunk);
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param world - World containing the chunk
+ * @param chunkX - X-coordinate of the chunk
+ * @param chunkZ - Z-coordinate of the chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ public static double @Nullable [] getRegionAverageTickTimes(@NotNull World world, int chunkX, int chunkZ) {
+ return server.getRegionAverageTickTimes(world, chunkX, chunkZ);
+ }
+ // Folia end - region TPS API

/**
* @deprecated All methods on this class have been deprecated, see the individual methods for replacements.
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 0ec885b97d655c03371840d739b47063494ed36f..1dc5d8c96786950fc98cada5bad981c0c716b154 100644
index 0ec885b97d655c03371840d739b47063494ed36f..b4e968938e7d213ca0628c953f35a7b9de6631b3 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2761,4 +2761,34 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@@ -2761,4 +2761,63 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
void allowPausing(@NotNull org.bukkit.plugin.Plugin plugin, boolean value);
// Paper end - API to check if the server is sleeping
Expand Down Expand Up @@ -88,5 +123,34 @@ index 0ec885b97d655c03371840d739b47063494ed36f..1dc5d8c96786950fc98cada5bad981c0
+ * @return TPS (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ double @Nullable [] getRegionTPS(@NotNull World world, int chunkX, int chunkZ);
+
+ /**
+ * Gets the average tick time from the region which owns the specified location, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param location The location for which to get the TPS
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ double @Nullable [] getRegionAverageTickTimes(@NotNull Location location);
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param chunk - The specified chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ double @Nullable [] getRegionAverageTickTimes(@NotNull Chunk chunk);
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param world - World containing the chunk
+ * @param chunkX - X-coordinate of the chunk
+ * @param chunkZ - Z-coordinate of the chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ double @Nullable [] getRegionAverageTickTimes(@NotNull World world, int chunkX, int chunkZ);
+ // Folia end - region TPS API
}
67 changes: 65 additions & 2 deletions folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 51b54104eb70f64a548f37eeab1a444678fafc8b..e0074e5b3446b8c7a188b3f5307b945765de5c71 100644
index 1e117e7278dfd30ee27d0fcf46c8dc8f5d8075e4..38c43ff847f16ac7530244df64b08e21ae58838c 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3034,4 +3034,69 @@ public final class CraftServer implements Server {
@@ -3034,4 +3034,132 @@ public final class CraftServer implements Server {
public void allowPausing(final Plugin plugin, final boolean value) {
this.console.addPluginAllowingSleep(plugin.getName(), value);
}
Expand Down Expand Up @@ -76,5 +76,68 @@ index 51b54104eb70f64a548f37eeab1a444678fafc8b..e0074e5b3446b8c7a188b3f5307b9457
+ };
+ }
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified location, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param location The location for which to get the TPS
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionAverageTickTimes(Location location) {
+ Preconditions.checkArgument(location != null, "Location cannot be null");
+
+ return this.getRegionAverageTickTimes(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param chunk - The specified chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionAverageTickTimes(org.bukkit.Chunk chunk) {
+ Preconditions.checkArgument(chunk != null, "Chunk cannot be null");
+
+ return this.getRegionAverageTickTimes(chunk.getWorld(), chunk.getX(), chunk.getZ());
+ }
+
+ /**
+ * Gets the average tick time from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param world - World containing the chunk
+ * @param chunkX - X-coordinate of the chunk
+ * @param chunkZ - Z-coordinate of the chunk
+ * @return Average tick time (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionAverageTickTimes(World world, int chunkX, int chunkZ) {
+ Preconditions.checkArgument(world != null, "World cannot be null");
+
+ return getAverageTickTimesFromRegion(((CraftWorld)world).getHandle(), chunkX, chunkZ);
+ }
+
+ private static double[] getAverageTickTimesFromRegion(ServerLevel world, int chunkX, int chunkZ) {
+ io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion<io.papermc.paper.threadedregions.TickRegions.TickRegionData, io.papermc.paper.threadedregions.TickRegions.TickRegionSectionData>
+ region = world.regioniser.getRegionAtSynchronised(chunkX, chunkZ);
+ if (region == null) {
+ return null;
+ } else {
+ io.papermc.paper.threadedregions.TickRegions.TickRegionData regionData = region.getData();
+ final long currTime = System.nanoTime();
+ final io.papermc.paper.threadedregions.TickRegionScheduler.RegionScheduleHandle regionScheduleHandle = regionData.getRegionSchedulingHandle();
+ return new double[] {
+ regionScheduleHandle.getTickReport5s(currTime).timePerTickData().segmentAll().average() / 1.0E6,
+ regionScheduleHandle.getTickReport15s(currTime).timePerTickData().segmentAll().average() / 1.0E6,
+ regionScheduleHandle.getTickReport1m(currTime).timePerTickData().segmentAll().average() / 1.0E6,
+ regionScheduleHandle.getTickReport5m(currTime).timePerTickData().segmentAll().average() / 1.0E6,
+ regionScheduleHandle.getTickReport15m(currTime).timePerTickData().segmentAll().average() / 1.0E6
+ };
+ }
+ }
+ // Folia end - region TPS API
}