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 Chunk or Location #232

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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/0006-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 <[email protected]>
Date: Mon, 3 Jun 2024 11:01:06 +0200
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 67c021f6d5d2afed92c7ceb4f511e3a43bbe2417..1da5ee2835ee729b3dfbdc633669cdf304e2eba3 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2397,6 +2397,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)
+ */
+ @NotNull
+ public double[] 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)
+ */
+ @NotNull
+ public double[] 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 d4c5b06fe4be177442ef1abaf1b223c6c2845930..8fb11dea6dbba71970c48af8d308c9cae4426af8 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2050,6 +2050,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)
+ */
+ @NotNull
+ public double[] 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)
+ */
+ @NotNull
+ public double[] getTPS(Chunk chunk);
+ // Folia end
+
// Paper start
/**
* Gets the active {@link org.bukkit.command.CommandMap}
52 changes: 52 additions & 0 deletions patches/server/0019-Add-TPS-From-Region.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Euphyllia Bierque <[email protected]>
Date: Mon, 3 Jun 2024 11:01:19 +0200
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 273c37b63df3f14488586f9217c7b19a8f3d8ad5..c383fa047c386952e7904b3d645b8f55498e4f25 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3114,6 +3114,41 @@ public final class CraftServer implements Server {
};
}

+ // Folia start
+ @Override
+ public double[] getTPS(org.bukkit.Location location) {
+ 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
+ public double[] getTPS(org.bukkit.Chunk chunk) {
+ final int x = chunk.getX();
+ final int z = chunk.getZ();
+ final ServerLevel world = ((CraftWorld) chunk.getWorld()).getHandle();
+ return getTPSFromRegion(world, x, z);
+ }
+
+ 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 new double[]{ 20.0, 20.0, 20.0, 20.0, 20.0 };
Euphillya marked this conversation as resolved.
Show resolved Hide resolved
+ } else {
+ io.papermc.paper.threadedregions.TickRegions.TickRegionData regionData = region.getData();
+ return new double[] {
+ regionData.getRegionSchedulingHandle().getTickReport5s(System.nanoTime()).tpsData().segmentAll().average(),
Euphillya marked this conversation as resolved.
Show resolved Hide resolved
+ regionData.getRegionSchedulingHandle().getTickReport15s(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport1m(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport5m(System.nanoTime()).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15m(System.nanoTime()).tpsData().segmentAll().average(),
+ };
+ }
+ }
+ // Folia end
+
// Paper start - adventure sounds
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {