Add Server#isGlobalTickThread

This method should be present in Paper, not just in Folia, given
that the GlobalRegionScheduler is present.

Additonally, add Server#isOwnedByCurrentRegion(World, int, int, int, int)
for checking of a rectangle of chunks is owned by the current region.
This commit is contained in:
Spottedleaf 2024-11-25 10:43:28 -08:00
parent c9731fc93d
commit 22dea6efbd
3 changed files with 61 additions and 7 deletions

View File

@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/org/bukkit/Server.java
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
boolean isOwnedByCurrentRegion(@NotNull Entity entity);
public boolean isGlobalTickThread();
// Paper end - Folia region threading API
+
+ // Paper start - API to check if the server is sleeping

View File

@ -631,6 +631,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ /**
+ * Returns whether the current thread is ticking a region and that the region being ticked
+ * owns the chunks in the rectangle specified by the min and max parameters.
+ * Specifically, this function checks that every chunk with position x in [minChunkX, maxChunkX] and
+ * position z in [minChunkZ, maxChunkZ] is owned by the current ticking region.
+ * @param world Specified world.
+ * @param minChunkX Specified x-coordinate of the minimum chunk position.
+ * @param minChunkZ Specified z-coordinate of the minimum chunk position.
+ * @param maxChunkX Specified x-coordinate of the maximum chunk position.
+ * @param maxChunkZ Specified z-coordinate of the maximum chunk position.
+ */
+ public static boolean isOwnedByCurrentRegion(@NotNull World world, int minChunkX, int minChunkZ, int maxChunkX, int maxChunkZ) {
+ return server.isOwnedByCurrentRegion(world, minChunkX, minChunkZ, maxChunkX, maxChunkZ);
+ }
+
+ /**
+ * Returns whether the current thread is ticking a region and that the region being ticked
+ * owns the specified entity. Note that this function is the only appropriate method of checking
+ * for ownership of an entity, as retrieving the entity's location is undefined unless the entity is owned
+ * by the current region.
@ -639,6 +654,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public static boolean isOwnedByCurrentRegion(@NotNull Entity entity) {
+ return server.isOwnedByCurrentRegion(entity);
+ }
+
+ /**
+ * Returns whether the current thread is ticking the global region.
+ * @see io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler
+ */
+ public static boolean isGlobalTickThread() {
+ return server.isGlobalTickThread();
+ }
+ // Paper end - Folia region threading API
+
@NotNull
@ -760,12 +783,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ /**
+ * Returns whether the current thread is ticking a region and that the region being ticked
+ * owns the chunks in the rectangle specified by the min and max parameters.
+ * Specifically, this function checks that every chunk with position x in [minChunkX, maxChunkX] and
+ * position z in [minChunkZ, maxChunkZ] is owned by the current ticking region.
+ * @param world Specified world.
+ * @param minChunkX Specified x-coordinate of the minimum chunk position.
+ * @param minChunkZ Specified z-coordinate of the minimum chunk position.
+ * @param maxChunkX Specified x-coordinate of the maximum chunk position.
+ * @param maxChunkZ Specified z-coordinate of the maximum chunk position.
+ */
+ boolean isOwnedByCurrentRegion(@NotNull World world, int minChunkX, int minChunkZ, int maxChunkX, int maxChunkZ);
+
+ /**
+ * Returns whether the current thread is ticking a region and that the region being ticked
+ * owns the specified entity. Note that this function is the only appropriate method of checking
+ * for ownership of an entity, as retrieving the entity's location is undefined unless the entity is owned
+ * by the current region.
+ * @param entity Specified entity.
+ */
+ boolean isOwnedByCurrentRegion(@NotNull Entity entity);
+
+ /**
+ * Returns whether the current thread is ticking the global region.
+ * @see io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler
+ */
+ public boolean isGlobalTickThread();
+ // Paper end - Folia region threading API
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java

View File

@ -1321,9 +1321,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ public final boolean isOwnedByCurrentRegion(World world, int minChunkX, int minChunkZ, int maxChunkX, int maxChunkZ) {
+ return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(
+ ((CraftWorld) world).getHandle(), minChunkX, minChunkZ, maxChunkX, maxChunkZ
+ );
+ }
+
+ @Override
+ public final boolean isOwnedByCurrentRegion(Entity entity) {
+ return ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandleRaw());
+ }
+
+ @Override
+ public final boolean isGlobalTickThread() {
+ return ca.spottedleaf.moonrise.common.util.TickThread.isTickThread();
+ }
+ // Paper end - Folia reagion threading API
+
static {