diff --git a/patches/api/API-to-check-if-the-server-is-sleeping.patch b/patches/api/API-to-check-if-the-server-is-sleeping.patch index 0bbc301a3f..c4d0ed1cb3 100644 --- a/patches/api/API-to-check-if-the-server-is-sleeping.patch +++ b/patches/api/API-to-check-if-the-server-is-sleeping.patch @@ -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 diff --git a/patches/api/Folia-scheduler-and-owned-region-API.patch b/patches/api/Folia-scheduler-and-owned-region-API.patch index 0628b07c29..303f258411 100644 --- a/patches/api/Folia-scheduler-and-owned-region-API.patch +++ b/patches/api/Folia-scheduler-and-owned-region-API.patch @@ -52,7 +52,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task. + */ + @NotNull ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer task, long delay, -+ @NotNull TimeUnit unit); ++ @NotNull TimeUnit unit); + + /** + * Schedules the specified task to be executed asynchronously after the initial delay has passed, @@ -65,7 +65,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task. + */ + @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer task, -+ long initialDelay, long period, @NotNull TimeUnit unit); ++ long initialDelay, long period, @NotNull TimeUnit unit); + + /** + * Attempts to cancel all tasks scheduled by the specified plugin. @@ -142,7 +142,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed. + */ + @Nullable ScheduledTask run(@NotNull Plugin plugin, @NotNull Consumer task, -+ @Nullable Runnable retired); ++ @Nullable Runnable retired); + + /** + * Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity @@ -161,7 +161,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed. + */ + @Nullable ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer task, -+ @Nullable Runnable retired, long delayTicks); ++ @Nullable Runnable retired, long delayTicks); + + /** + * Schedules a repeating task with the given delay and period. If the task failed to schedule because the scheduler @@ -181,7 +181,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed. + */ + @Nullable ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer task, -+ @Nullable Runnable retired, long initialDelayTicks, long periodTicks); ++ @Nullable Runnable retired, long initialDelayTicks, long periodTicks); +} diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java new file mode 100644 @@ -239,7 +239,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return The {@link ScheduledTask} that represents the scheduled task. + */ + @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer task, -+ long initialDelayTicks, long periodTicks); ++ long initialDelayTicks, long periodTicks); + + /** + * Attempts to cancel all tasks scheduled by the specified plugin. @@ -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 diff --git a/patches/server/Folia-scheduler-and-owned-region-API.patch b/patches/server/Folia-scheduler-and-owned-region-API.patch index 863eb9a51c..ed5dfc215b 100644 --- a/patches/server/Folia-scheduler-and-owned-region-API.patch +++ b/patches/server/Folia-scheduler-and-owned-region-API.patch @@ -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 {