From 5edf646028bfbfd048cdbf54293392406f0f81e0 Mon Sep 17 00:00:00 2001 From: Euphyllia Bierque Date: Sun, 15 Dec 2024 22:34:39 +0100 Subject: [PATCH] Add TPS From Region --- patches/api/0005-Add-TPS-From-Region.patch | 68 +++++++++++++++++++ patches/server/0020-Add-TPS-From-Region.patch | 60 ++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 patches/api/0005-Add-TPS-From-Region.patch create mode 100644 patches/server/0020-Add-TPS-From-Region.patch diff --git a/patches/api/0005-Add-TPS-From-Region.patch b/patches/api/0005-Add-TPS-From-Region.patch new file mode 100644 index 000000000..89d6c9db7 --- /dev/null +++ b/patches/api/0005-Add-TPS-From-Region.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Euphyllia Bierque +Date: Sun, 15 Dec 2024 22:32:09 +0100 +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 8ab94f8189ebd9d4158231871abdebec399deb2c..733a532dc2b3103471a9695034979c80b1db4acd 100644 +--- a/src/main/java/org/bukkit/Bukkit.java ++++ b/src/main/java/org/bukkit/Bukkit.java +@@ -2429,6 +2429,28 @@ public final class Bukkit { + } + // Paper end + ++ // Folia start ++ /** ++ * 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), or null if the region doesn't exist ++ */ ++ public double @Nullable [] getTPS(Location location) { ++ return server.getTPS(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), or null if the region doesn't exist ++ */ ++ public double @Nullable [] getTPS(Chunk chunk){ ++ return server.getTPS(chunk); ++ } ++ // Folia end ++ + /** + * 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 ad816538b30079c62d5e1eb98c6f4b61e12e8d47..ee53473d062f32dcc7c00a6cf4516df2a3e79161 100644 +--- a/src/main/java/org/bukkit/Server.java ++++ b/src/main/java/org/bukkit/Server.java +@@ -2076,6 +2076,24 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi + double getAverageTickTime(); + // Paper end + ++ // Folia start ++ /** ++ * 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), or null if the region doesn't exist ++ */ ++ 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), or null if the region doesn't exist ++ */ ++ public double @Nullable [] getTPS(Chunk chunk); ++ // Folia end ++ + // Paper start + /** + * Gets the active {@link org.bukkit.command.CommandMap} diff --git a/patches/server/0020-Add-TPS-From-Region.patch b/patches/server/0020-Add-TPS-From-Region.patch new file mode 100644 index 000000000..2d276f130 --- /dev/null +++ b/patches/server/0020-Add-TPS-From-Region.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Euphyllia Bierque +Date: Sun, 15 Dec 2024 22:32:20 +0100 +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 567e12e24ece2cd823b73e7337b10eb89995da21..a92eae6b4cb13d66f55c1cf54bf46d825783843d 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -3105,6 +3105,49 @@ public final class CraftServer implements Server { + }; + } + ++ // Folia start ++ @Override @Nullable ++ public double[] getTPS(org.bukkit.Location location) { ++ Preconditions.checkArgument(location != null, "Location cannot be null"); ++ Preconditions.checkArgument(location.getWorld() != null, "World cannot be null"); ++ ++ final int x = location.blockX() >> 4; ++ final int z = location.blockZ() >> 4; ++ final ServerLevel world = ((CraftWorld) location.getWorld()).getHandle(); ++ return getTPSFromRegion(world, x, z); ++ } ++ ++ @Override @Nullable ++ public double[] getTPS(org.bukkit.Chunk chunk) { ++ Preconditions.checkArgument(chunk != null, "Chunk cannot be null"); ++ ++ final int x = chunk.getX(); ++ final int z = chunk.getZ(); ++ final ServerLevel world = ((CraftWorld) chunk.getWorld()).getHandle(); ++ return getTPSFromRegion(world, x, z); ++ } ++ ++ @Nullable ++ private double[] getTPSFromRegion(ServerLevel world, int x, int z) { ++ io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion ++ region = world.regioniser.getRegionAtSynchronised(x, z); ++ 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 ++ + // Paper start - adventure sounds + @Override + public void playSound(final net.kyori.adventure.sound.Sound sound) {