diff --git a/patches/api/0006-Add-executor-for-threaded-regions.patch b/patches/api/0006-Add-executor-for-threaded-regions.patch new file mode 100644 index 0000000000..c825c8b172 --- /dev/null +++ b/patches/api/0006-Add-executor-for-threaded-regions.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: jdkeke142 +Date: Mon, 3 Apr 2023 04:56:15 +0200 +Subject: [PATCH] Add executor for threaded regions + +Added GlobalRegionScheduler#getExecutor and RegionScheduler#getExecutor +to get respectively an executor of the global region +and to get an executor of a corresponding region +at a location + +diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java +index 712af8218d5a81f731a227bcaccd7a1dc54628be..4f23f608ba5cf71425235793bfcc5a4073f3b8e5 100644 +--- a/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java ++++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java +@@ -2,6 +2,8 @@ package io.papermc.paper.threadedregions.scheduler; + + import org.bukkit.plugin.Plugin; + import org.jetbrains.annotations.NotNull; ++ ++import java.util.concurrent.Executor; + import java.util.function.Consumer; + + /** +@@ -49,6 +51,14 @@ public interface GlobalRegionScheduler { + @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer task, + long initialDelayTicks, long periodTicks); + ++ /** ++ * Returns an executor that will run tasks on the global region. ++ * ++ * @param plugin The plugin that owns the task ++ * @return An executor associated with the global region ++ */ ++ @NotNull Executor getExecutor(@NotNull Plugin plugin); ++ + /** + * Attempts to cancel all tasks scheduled by the specified plugin. + * @param plugin Specified plugin. +diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionScheduler.java +index 7a7afd4ffb323dd55db13ef1a49c6594aeb5ffea..2c28425be48b5ec8bcbcaa4e002a34e8f445c60d 100644 +--- a/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionScheduler.java ++++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionScheduler.java +@@ -5,6 +5,8 @@ import org.bukkit.World; + import org.bukkit.entity.Entity; + import org.bukkit.plugin.Plugin; + import org.jetbrains.annotations.NotNull; ++ ++import java.util.concurrent.Executor; + import java.util.function.Consumer; + + /** +@@ -123,4 +125,26 @@ public interface RegionScheduler { + long initialDelayTicks, long periodTicks) { + return this.runAtFixedRate(plugin, location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, initialDelayTicks, periodTicks); + } ++ ++ /** ++ * Returns an executor that will run tasks on the region which owns the location. ++ * ++ * @param plugin The plugin that owns the task ++ * @param world The world of the region that owns the task ++ * @param chunkX The chunk X coordinate of the region that owns the task ++ * @param chunkZ The chunk Z coordinate of the region that owns the task ++ * @return An executor associated with the given region ++ */ ++ @NotNull Executor getExecutor(@NotNull Plugin plugin, @NotNull World world, int chunkX, int chunkZ); ++ ++ /** ++ * Returns an executor that will run tasks on the region which owns the location. ++ * ++ * @param plugin The plugin that owns the task ++ * @param location The location at which the region executing should own ++ * @return An executor associated with the given region ++ */ ++ default @NotNull Executor getExecutor(@NotNull Plugin plugin, @NotNull Location location) { ++ return getExecutor(plugin, location.getWorld(),location.getBlockX() >> 4, location.getBlockZ() >> 4); ++ } + } diff --git a/patches/server/0017-Add-executor-for-threaded-regions.patch b/patches/server/0017-Add-executor-for-threaded-regions.patch new file mode 100644 index 0000000000..a40e23ad55 --- /dev/null +++ b/patches/server/0017-Add-executor-for-threaded-regions.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: jdkeke142 +Date: Mon, 3 Apr 2023 04:48:44 +0200 +Subject: [PATCH] Add executor for threaded regions + +Added GlobalRegionScheduler#getExecutor and RegionScheduler#getExecutor +to get respectively an executor of the global region +and to get an executor of a corresponding region +at a location + +diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaGlobalRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaGlobalRegionScheduler.java +index eac8bc531dc11aa652bafd73e50d7930cbca19e5..3a0566d0136cbfbaa8e12936ebdba0678e9e62c4 100644 +--- a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaGlobalRegionScheduler.java ++++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaGlobalRegionScheduler.java +@@ -8,6 +8,7 @@ import org.bukkit.plugin.Plugin; + import java.lang.invoke.VarHandle; + import java.util.ArrayList; + import java.util.List; ++import java.util.concurrent.Executor; + import java.util.function.Consumer; + import java.util.logging.Level; + +@@ -124,6 +125,15 @@ public final class FoliaGlobalRegionScheduler implements GlobalRegionScheduler { + } + } + ++ @Override ++ public Executor getExecutor(final Plugin plugin) { ++ Validate.notNull(plugin, "Plugin may not be null"); ++ return command -> { ++ Validate.notNull(command, "Command cannot be null"); ++ this.execute(plugin, command); ++ }; ++ } ++ + private void scheduleInternal(final GlobalScheduledTask task, final long delay) { + // note: delay > 0 + synchronized (this.stateLock) { +diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaRegionScheduler.java +index aa10f3273e3bb35cf59d324644c269893cc12e99..81ce6c09159e98e8843dfe578526f9120c58265f 100644 +--- a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaRegionScheduler.java ++++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaRegionScheduler.java +@@ -24,6 +24,7 @@ import java.lang.invoke.VarHandle; + import java.util.ArrayList; + import java.util.Iterator; + import java.util.List; ++import java.util.concurrent.Executor; + import java.util.function.Consumer; + import java.util.logging.Level; + +@@ -139,6 +140,16 @@ public final class FoliaRegionScheduler implements RegionScheduler { + return ret; + } + ++ @Override ++ public Executor getExecutor(final Plugin plugin, final World world, final int chunkX, final int chunkZ) { ++ Validate.notNull(plugin, "Plugin may not be null"); ++ Validate.notNull(world, "World may not be null"); ++ return command -> { ++ Validate.notNull(command, "Command cannot be null"); ++ this.execute(plugin, world, chunkX, chunkZ, command); ++ }; ++ } ++ + public void tick() { + SCHEDULER_DATA.get().tick(); + }