-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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} |
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 }; | ||
+ } else { | ||
+ io.papermc.paper.threadedregions.TickRegions.TickRegionData regionData = region.getData(); | ||
+ return new double[] { | ||
+ regionData.getRegionSchedulingHandle().getTickReport5s(System.nanoTime()).tpsData().segmentAll().average(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to at least store the time in nano seconds? As i remember it's not the fastest method to be called so many times There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, calling it every time is not a good idea, so I preferred to store it in a variable (like /tps) |
||
+ 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good behavior, and it's totally undocumented, maybe change to
Optional<double[]>
/double @Nullable []
or throw and error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified it with a Nullable, which I think is the best option.