0
0
mirror of https://github.com/PaperMC/Folia.git synced 2025-08-05 22:11:40 +00:00
Files
Folia/folia-server/paper-patches/features/0007-Add-TPS-From-Region.patch
2025-05-25 15:34:08 -07:00

81 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Euphyllia Bierque <bierque.euphyllia@gmail.com>
Date: Tue, 28 Jan 2025 16:35:13 -0800
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 1e605345b2911193b4500a7f84ea8ace318842e5..7c30289ff28c4f0b91597da9c4aa192e7ff559cc 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3277,4 +3277,69 @@ public final class CraftServer implements Server {
public void allowPausing(final Plugin plugin, final boolean value) {
this.console.addPluginAllowingSleep(plugin.getName(), value);
}
+
+ // Folia start - region TPS API
+ /**
+ * Gets the TPS 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 TPS (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionTPS(Location location) {
+ Preconditions.checkArgument(location != null, "Location cannot be null");
+
+ return this.getRegionTPS(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
+ }
+
+ /**
+ * Gets the TPS from the region which owns the specified chunk, or {@code null} if no region owns
+ * the specified location.
+ *
+ * @param chunk - The specified chunk
+ * @return TPS (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionTPS(org.bukkit.Chunk chunk) {
+ Preconditions.checkArgument(chunk != null, "Chunk cannot be null");
+
+ return this.getRegionTPS(chunk.getWorld(), chunk.getX(), chunk.getZ());
+ }
+
+ /**
+ * Gets the TPS 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 TPS (5s, 15s, 1m, 5m, 15m), or null if the region doesn't exist
+ */
+ @Override
+ public double[] getRegionTPS(World world, int chunkX, int chunkZ) {
+ Preconditions.checkArgument(world != null, "World cannot be null");
+
+ return getTPSFromRegion(((CraftWorld)world).getHandle(), chunkX, chunkZ);
+ }
+
+ private static double[] getTPSFromRegion(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).tpsData().segmentAll().average(),
+ regionScheduleHandle.getTickReport15s(currTime).tpsData().segmentAll().average(),
+ regionScheduleHandle.getTickReport1m(currTime).tpsData().segmentAll().average(),
+ regionScheduleHandle.getTickReport5m(currTime).tpsData().segmentAll().average(),
+ regionScheduleHandle.getTickReport15m(currTime).tpsData().segmentAll().average(),
+ };
+ }
+ }
+ // Folia end - region TPS API
}