From 7b38e623293fe79ade2a7dd6c57f27d66b0b310e Mon Sep 17 00:00:00 2001 From: Biquaternions Date: Thu, 4 Sep 2025 16:06:21 -0500 Subject: [PATCH] Expanded API to support MSPT --- .../features/0004-Add-TPS-From-Region.patch | 72 +++++++++++++++++-- .../features/0007-Add-TPS-From-Region.patch | 67 ++++++++++++++++- 2 files changed, 133 insertions(+), 6 deletions(-) diff --git a/folia-api/paper-patches/features/0004-Add-TPS-From-Region.patch b/folia-api/paper-patches/features/0004-Add-TPS-From-Region.patch index 8d8e609502..1282d8d413 100644 --- a/folia-api/paper-patches/features/0004-Add-TPS-From-Region.patch +++ b/folia-api/paper-patches/features/0004-Add-TPS-From-Region.patch @@ -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 3bde4ad79ade5aae18e9073307f637717e8dd9e3..85b778980e762835ac278528087e91b2e3effb43 100644 +index 3bde4ad79ade5aae18e9073307f637717e8dd9e3..eb03ac7479bd4bb7fbb2204d35e6846d41fd5c21 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java -@@ -3000,6 +3000,42 @@ public final class Bukkit { +@@ -3000,6 +3000,77 @@ public final class Bukkit { return server.isGlobalTickThread(); } // Paper end - Folia region threading API @@ -47,15 +47,50 @@ index 3bde4ad79ade5aae18e9073307f637717e8dd9e3..85b778980e762835ac278528087e91b2 + 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 9bab00ab10c78908090c8a1a12d4c84e9324b08b..a0540d7de5c2536aed5231f9e67b73345817921d 100644 +index 9bab00ab10c78908090c8a1a12d4c84e9324b08b..75d66aa4c44ed87fbc5a771768007ddf017c8d8d 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java -@@ -2723,4 +2723,34 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi +@@ -2723,4 +2723,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 @@ -88,5 +123,34 @@ index 9bab00ab10c78908090c8a1a12d4c84e9324b08b..a0540d7de5c2536aed5231f9e67b7334 + * @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 } diff --git a/folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch b/folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch index c310491bc1..9489ba2009 100644 --- a/folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch +++ b/folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch @@ -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 9b182315682b5795b2cb6438ea440591ddddc5a3..d2db175fd7bfc5ff38e3945c8744858265212b1d 100644 +index 53c8009cd4886ddcf1f2ea72b6e51b308c72719c..8a2b8fc033f08e5bc6aaa94ef263b88156345eae 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -3253,4 +3253,69 @@ public final class CraftServer implements Server { +@@ -3253,4 +3253,132 @@ public final class CraftServer implements Server { public void allowPausing(final Plugin plugin, final boolean value) { this.console.addPluginAllowingSleep(plugin.getName(), value); } @@ -76,5 +76,68 @@ index 9b182315682b5795b2cb6438ea440591ddddc5a3..d2db175fd7bfc5ff38e3945c87448582 + }; + } + } ++ ++ /** ++ * 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 ++ 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 }