9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Parallel World Ticking API for monitoring tools (#493)

* Parallel World Ticking API for monitoring tools
This commit is contained in:
𝑩𝒊𝒒𝒖𝒂𝒕𝒆𝒓𝒏𝒊𝒐𝒏𝒔
2025-09-08 21:28:51 -05:00
committed by GitHub
parent a33bcd004d
commit a9adcf48e5
15 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Biquaternions <biquaternions@serlith.net>
Date: Tue, 2 Sep 2025 13:54:37 -0500
Subject: [PATCH] Fish: Parallel World Ticking API
Original license: MIT
Original project: https://github.com/Biquaternions/Fish
This patch provides an API for performance monitoring plugins like PurpurBars.
A better approach would be to include an event when the world is done ticking,
which will allow to re-use the RollingAverage logic from Spark and Minecraft internals.
However, since every fork developer will want to have said event into their own namespace,
it will be virtually impossible to provide a universal API.
With this approach only new methods are added into already existing Bukkit API, and the same
naming conventions as Bukkit were used, which means there's a bigger chance of this API to
get standarized.
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 82e56218b5c854a16851b75e3145e301d5fedab0..e12d161ac49f4725faf3ad2d13972524f625b862 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2929,4 +2929,15 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
// Leaves start - Photographer API
@NotNull org.leavesmc.leaves.entity.photographer.PhotographerManager getPhotographerManager();
// Leaves end - Photographer API
+
+ // Fish start - Parallel World Ticking API
+ /**
+ * Returns whether the software has the Parallel World Ticking feature enabled
+ *
+ * @return If the Parallel World Ticking feature is enabled
+ */
+ public default boolean isParallelWorldTickingEnabled() {
+ return false;
+ }
+ // Fish end - Parallel World Ticking API
}
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index bb9fe9a6c3116e83d2ebd98f81298454f6677ccc..5b02d1938ddaf02c7f227271c0dc27702a41fc83 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -4494,6 +4494,25 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@NotNull
public Collection<GeneratedStructure> getStructures(int x, int z, @NotNull Structure structure);
+ // Fish start - Parallel World Ticking API
+ /**
+ * Get a sample of the world last tick times (in nanos)
+ *
+ * @return A sample of the world last tick times (in nanos)
+ */
+ public default long @NotNull [] getTickTimes() {
+ return new long[0];
+ }
+ /**
+ * Get the world's average tick time (in millis)
+ *
+ * @return World's local average tick time (in millis)
+ */
+ public default double getAverageTickTime () {
+ return 0.0;
+ }
+ // Fish end - Parallel World Ticking API
+
/**
* Represents various map environment types that a world may be
*/

View File

@@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Biquaternions <biquaternions@serlith.net>
Date: Tue, 2 Sep 2025 13:54:37 -0500
Subject: [PATCH] Fish: Parallel World Ticking API
Original license: MIT
Original project: https://github.com/Biquaternions/Fish
This patch provides an API for performance monitoring plugins like PurpurBars.
A better approach would be to include an event when the world is done ticking,
which will allow to re-use the RollingAverage logic from Spark and Minecraft internals.
However, since every fork developer will want to have said event into their own namespace,
it will be virtually impossible to provide a universal API.
With this approach only new methods are added into already existing Bukkit API, and the same
naming conventions as Bukkit were used, which means there's a bigger chance of this API to
get standarized.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index dfafd3125438b6a74f15a749599acfd00918c50a..bcda5dd6fe3741518fea263b4790ea33bb9729cb 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3366,4 +3366,11 @@ public final class CraftServer implements Server {
return photographerManager;
}
// Leaves end - replay mod api
+
+ // Fish start - Parallel World Ticking API
+ @Override
+ public boolean isParallelWorldTickingEnabled() {
+ return org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled;
+ }
+ // Fish end - Parallel World Ticking API
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index ee5f342995a335593932a497c2bafd36d34cecb2..a16390fc13e1baf3cffbcfec5cc410a72ed47367 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2556,4 +2556,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return POINTERS_SUPPLIER.view(this);
}
// Paper end
+
+ // Fish start - Parallel World Ticking API
+ @Override
+ public long @NotNull [] getTickTimes() {
+ return this.world.tickTimes5s.getTimes();
+ }
+ @Override
+ public double getAverageTickTime() {
+ return this.world.tickTimes5s.getAverage();
+ }
+ // Fish end - Parallel World Ticking API
}