Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TPS From Region #310

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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: 72 additions & 0 deletions patches/api/0005-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Euphyllia Bierque <bierque.euphyllia@gmail.com>
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..5571430fd1b9cae2b4e5d634f6d5560792aeeeb8 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2429,6 +2429,30 @@ 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
+ */
+ @Nullable
+ public static double[] getTPS(@NotNull 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
+ */
+ @Nullable
+ public static double[] getTPS(@NotNull 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..d52f642aadea9ec19a769f43d995f9c6fa0934fb 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2076,6 +2076,26 @@ 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
+ */
+ @Nullable
+ public double[] getTPS(@NotNull 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
+ */
+ @Nullable
+ public double[] getTPS(@NotNull Chunk chunk);
+ // Folia end
+
// Paper start
/**
* Gets the active {@link org.bukkit.command.CommandMap}
60 changes: 60 additions & 0 deletions patches/server/0020-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Euphyllia Bierque <bierque.euphyllia@gmail.com>
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<io.papermc.paper.threadedregions.TickRegions.TickRegionData, io.papermc.paper.threadedregions.TickRegions.TickRegionSectionData>
+ 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) {
Loading