Skip to content

Commit

Permalink
Merge pull request #4 from Euphillya/master
Browse files Browse the repository at this point in the history
Add TPS From Region
  • Loading branch information
Q2297045667 authored Dec 16, 2024
2 parents 8af1aef + 5edf646 commit d9422c8
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
68 changes: 68 additions & 0 deletions patches/api/0005-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Euphyllia Bierque <[email protected]>
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}
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 <[email protected]>
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) {

0 comments on commit d9422c8

Please sign in to comment.