mirror of
https://github.com/PaperMC/Folia.git
synced 2024-11-24 12:25:23 +01:00
New scheduler API
Now, entity/global/location schedulers implement a generic run, runDelayed, and runAtFixedRate methods that provide a ScheduledTask value that can be used to interact with the scheduled task. Add also an async task scheduler that implements the same methods, except the delays/periods are in time and not ticks, as the scheduler is independent of the server tick process. Additionally, throw on some unimplemented APIs now.
This commit is contained in:
parent
0da953539b
commit
50ad6c3131
@ -6,17 +6,74 @@ Subject: [PATCH] Region scheduler API
|
||||
Add both a location based scheduler, an entity based scheduler,
|
||||
and a global region scheduler.
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/AsyncScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/AsyncScheduler.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..64d1fe385d30f1f5ab82d35fe66e268da13346b1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/AsyncScheduler.java
|
||||
@@ -0,0 +1,50 @@
|
||||
+package io.papermc.paper.threadedregions.scheduler;
|
||||
+
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import java.util.concurrent.TimeUnit;
|
||||
+import java.util.function.Consumer;
|
||||
+
|
||||
+/**
|
||||
+ * Scheduler that may be used by plugins to schedule tasks to execute asynchronously from the server tick process.
|
||||
+ */
|
||||
+public interface AsyncScheduler {
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules the specified task to be executed asynchronously immediately.
|
||||
+ * @param plugin Plugin which owns the specified task.
|
||||
+ * @param task Specified task.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runNow(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules the specified task to be executed asynchronously after the time delay has passed.
|
||||
+ * @param plugin Plugin which owns the specified task.
|
||||
+ * @param task Specified task.
|
||||
+ * @param delay The time delay to pass before the task should be executed.
|
||||
+ * @param unit The time unit for the time delay.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task, long delay,
|
||||
+ @NotNull TimeUnit unit);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules the specified task to be executed asynchronously after the initial delay has passed,
|
||||
+ * and then periodically executed with the specified period.
|
||||
+ * @param plugin Plugin which owns the specified task.
|
||||
+ * @param task Specified task.
|
||||
+ * @param initialDelay The time delay to pass before the first execution of the task.
|
||||
+ * @param period The time between task executions after the first execution of the task.
|
||||
+ * @param unit The time unit for the initial delay and period.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task,
|
||||
+ long initialDelay, long period, @NotNull TimeUnit unit);
|
||||
+
|
||||
+ /**
|
||||
+ * Attempts to cancel all tasks scheduled by the specified plugin.
|
||||
+ * @param plugin Specified plugin.
|
||||
+ */
|
||||
+ public void cancelTasks(@NotNull Plugin plugin);
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4193b13f1f51c2fb8da76f3e03187d859eaa8e10
|
||||
index 0000000000000000000000000000000000000000..9c4ee07a86104f3601ba6d8a911197dbe1a17102
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/EntityScheduler.java
|
||||
@@ -0,0 +1,47 @@
|
||||
@@ -0,0 +1,103 @@
|
||||
+package io.papermc.paper.threadedregions.scheduler;
|
||||
+
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import java.util.function.Consumer;
|
||||
+
|
||||
+/**
|
||||
+ * An entity can move between worlds with an arbitrary tick delay, be temporarily removed
|
||||
@ -55,20 +112,76 @@ index 0000000000000000000000000000000000000000..4193b13f1f51c2fb8da76f3e03187d85
|
||||
+ * will be invoked (but never both), or {@code false} indicating neither the run nor retired function will be invoked
|
||||
+ * since the scheduler has been retired.
|
||||
+ */
|
||||
+ public boolean execute(@NotNull final Plugin plugin, @NotNull final Runnable run, @Nullable final Runnable retired,
|
||||
+ final long delay);
|
||||
+ public boolean execute(@NotNull Plugin plugin, @NotNull Runnable run, @Nullable Runnable retired, long delay);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task to execute on the next tick. If the task failed to schedule because the scheduler is retired (entity
|
||||
+ * removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
|
||||
+ * or the retired callback will be invoked if the scheduler is retired.
|
||||
+ * Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
|
||||
+ * other entities, load chunks, load worlds, modify ticket levels, etc.
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
|
||||
+ * </p>
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed.
|
||||
+ */
|
||||
+ public @Nullable ScheduledTask run(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task,
|
||||
+ @Nullable Runnable retired);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity
|
||||
+ * removed), then returns {@code null}. Otherwise, either the task callback will be invoked after the specified delay,
|
||||
+ * or the retired callback will be invoked if the scheduler is retired.
|
||||
+ * Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
|
||||
+ * other entities, load chunks, load worlds, modify ticket levels, etc.
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
|
||||
+ * </p>
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
|
||||
+ * @param delayTicks The delay, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed.
|
||||
+ */
|
||||
+ public @Nullable ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task,
|
||||
+ @Nullable Runnable retired, int delayTicks);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a repeating task with the given delay and period. If the task failed to schedule because the scheduler
|
||||
+ * is retired (entity removed), then returns {@code null}. Otherwise, either the task callback will be invoked after
|
||||
+ * the specified delay, or the retired callback will be invoked if the scheduler is retired.
|
||||
+ * Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, remove
|
||||
+ * other entities, load chunks, load worlds, modify ticket levels, etc.
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
|
||||
+ * </p>
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @param retired Retire callback to run if the entity is retired before the run callback can be invoked, may be null.
|
||||
+ * @param initialDelayTicks The initial delay, in ticks.
|
||||
+ * @param periodTicks The period, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task, or {@code null} if the entity has been removed.
|
||||
+ */
|
||||
+ public @Nullable ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task,
|
||||
+ @Nullable Runnable retired, int initialDelayTicks, int 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
|
||||
index 0000000000000000000000000000000000000000..c13c89c87a4e6fd441cac8d3c8cd5b283915467f
|
||||
index 0000000000000000000000000000000000000000..f2d2565d903af90f6909319c811a49162f972e27
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/GlobalRegionScheduler.java
|
||||
@@ -0,0 +1,22 @@
|
||||
@@ -0,0 +1,57 @@
|
||||
+package io.papermc.paper.threadedregions.scheduler;
|
||||
+
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import java.util.function.Consumer;
|
||||
+
|
||||
+/**
|
||||
+ * The global region task scheduler may be used to schedule tasks that will execute on the global region.
|
||||
@ -84,21 +197,56 @@ index 0000000000000000000000000000000000000000..c13c89c87a4e6fd441cac8d3c8cd5b28
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param run The task to execute
|
||||
+ */
|
||||
+ public void execute(@NotNull final Plugin plugin, @NotNull final Runnable run);
|
||||
+ public void execute(@NotNull Plugin plugin, @NotNull Runnable run);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task to be executed on the global region on the next tick.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask run(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task to be executed on the global region after the specified delay in ticks.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @param delayTicks The delay, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task, int delayTicks);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a repeating task to be executed on the global region after the initial delay with the
|
||||
+ * specified period.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param task The task to execute
|
||||
+ * @param initialDelayTicks The initial delay, in ticks.
|
||||
+ * @param periodTicks The period, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task,
|
||||
+ int initialDelayTicks, int periodTicks);
|
||||
+
|
||||
+ /**
|
||||
+ * Attempts to cancel all tasks scheduled by the specified plugin.
|
||||
+ * @param plugin Specified plugin.
|
||||
+ */
|
||||
+ public void cancelTasks(@NotNull Plugin plugin);
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionisedScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionisedScheduler.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..210a3dce74959efd7ac0ca9a92a2ad8815844246
|
||||
index 0000000000000000000000000000000000000000..4912d47e3daa4071bc82b1a32a19c8ea3348e0cc
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/RegionisedScheduler.java
|
||||
@@ -0,0 +1,26 @@
|
||||
@@ -0,0 +1,60 @@
|
||||
+package io.papermc.paper.threadedregions.scheduler;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.entity.Entity;
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import java.util.function.Consumer;
|
||||
+
|
||||
+/**
|
||||
+ * The region task scheduler can be used to schedule tasks by location to be executed on the region which owns the location.
|
||||
@ -117,13 +265,164 @@ index 0000000000000000000000000000000000000000..210a3dce74959efd7ac0ca9a92a2ad88
|
||||
+ * @param location The location at which the region executing should own
|
||||
+ * @param run The task to execute
|
||||
+ */
|
||||
+ public void execute(@NotNull final Plugin plugin, @NotNull final Location location, @NotNull final Runnable run);
|
||||
+ public void execute(@NotNull Plugin plugin, @NotNull Location location, @NotNull Runnable run);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task to be executed on the region which owns the location on the next tick.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param location The location at which the region executing should own
|
||||
+ * @param task The task to execute
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask run(@NotNull Plugin plugin, @NotNull Location location, @NotNull Consumer<ScheduledTask> task);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a task to be executed on the region which owns the location after the specified delay in ticks.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param location The location at which the region executing should own
|
||||
+ * @param task The task to execute
|
||||
+ * @param delayTicks The delay, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Location location, @NotNull Consumer<ScheduledTask> task,
|
||||
+ int delayTicks);
|
||||
+
|
||||
+ /**
|
||||
+ * Schedules a repeating task to be executed on the region which owns the location after the initial delay with the
|
||||
+ * specified period.
|
||||
+ * @param plugin The plugin that owns the task
|
||||
+ * @param location The location at which the region executing should own
|
||||
+ * @param task The task to execute
|
||||
+ * @param initialDelayTicks The initial delay, in ticks.
|
||||
+ * @param periodTicks The period, in ticks.
|
||||
+ * @return The {@link ScheduledTask} that represents the scheduled task.
|
||||
+ */
|
||||
+ public @NotNull ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Location location, @NotNull Consumer<ScheduledTask> task,
|
||||
+ int initialDelayTicks, int periodTicks);
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/ScheduledTask.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/ScheduledTask.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..fa4ac300d3721b2d6d84b95618d3305874cb803d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/ScheduledTask.java
|
||||
@@ -0,0 +1,112 @@
|
||||
+package io.papermc.paper.threadedregions.scheduler;
|
||||
+
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a task scheduled to a scheduler.
|
||||
+ */
|
||||
+public interface ScheduledTask {
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the plugin that scheduled this task.
|
||||
+ * @return the plugin that scheduled this task.
|
||||
+ */
|
||||
+ public @NotNull Plugin getOwningPlugin();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns whether this task executes on a fixed period, as opposed to executing only once.
|
||||
+ * @return whether this task executes on a fixed period, as opposed to executing only once.
|
||||
+ */
|
||||
+ public boolean isRepeatingTask();
|
||||
+
|
||||
+ /**
|
||||
+ * Attempts to cancel this task, returning the result of the attempt. In all cases, if the task is currently
|
||||
+ * being executed no attempt is made to halt the task, however any executions in the future are halted.
|
||||
+ * @return the result of the cancellation attempt.
|
||||
+ */
|
||||
+ public @NotNull CancelledState cancel();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the current execution state of this task.
|
||||
+ * @return the current execution state of this task.
|
||||
+ */
|
||||
+ public @NotNull ExecutionState getExecutionState();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns whether the current execution state is {@link ExecutionState#CANCELLED} or {@link ExecutionState#CANCELLED_RUNNING}.
|
||||
+ * @return whether the current execution state is {@link ExecutionState#CANCELLED} or {@link ExecutionState#CANCELLED_RUNNING}.
|
||||
+ */
|
||||
+ public default boolean isCancelled() {
|
||||
+ final ExecutionState state = this.getExecutionState();
|
||||
+ return state == ExecutionState.CANCELLED || state == ExecutionState.CANCELLED_RUNNING;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Represents the result of attempting to cancel a task.
|
||||
+ */
|
||||
+ public enum CancelledState {
|
||||
+ /**
|
||||
+ * The task (repeating or not) has been successfully cancelled by the caller thread. The task is not executing
|
||||
+ * currently, and it will not begin execution in the future.
|
||||
+ */
|
||||
+ CANCELLED_BY_CALLER,
|
||||
+ /**
|
||||
+ * The task (repeating or not) is already cancelled. The task is not executing currently, and it will not
|
||||
+ * begin execution in the future.
|
||||
+ */
|
||||
+ CANCELLED_ALREADY,
|
||||
+
|
||||
+ /**
|
||||
+ * The task is not a repeating task, and could not be cancelled because the task is being executed.
|
||||
+ */
|
||||
+ RUNNING,
|
||||
+ /**
|
||||
+ * The task is not a repeating task, and could not be cancelled because the task has already finished execution.
|
||||
+ */
|
||||
+ ALREADY_EXECUTED,
|
||||
+
|
||||
+ /**
|
||||
+ * The caller thread successfully stopped future executions of a repeating task, but the task is currently
|
||||
+ * being executed.
|
||||
+ */
|
||||
+ NEXT_RUNS_CANCELLED,
|
||||
+
|
||||
+ /**
|
||||
+ * The repeating task's future executions are cancelled already, but the task is currently
|
||||
+ * being executed.
|
||||
+ */
|
||||
+ NEXT_RUNS_CANCELLED_ALREADY,
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Represents the current execution state of the task.
|
||||
+ */
|
||||
+ public enum ExecutionState {
|
||||
+ /**
|
||||
+ * The task is currently not executing, but may begin execution in the future.
|
||||
+ */
|
||||
+ IDLE,
|
||||
+
|
||||
+ /**
|
||||
+ * The task is currently executing.
|
||||
+ */
|
||||
+ RUNNING,
|
||||
+
|
||||
+ /**
|
||||
+ * The task is not repeating, and the task finished executing.
|
||||
+ */
|
||||
+ FINISHED,
|
||||
+
|
||||
+ /**
|
||||
+ * The task is not executing and will not begin execution in the future. If this task is not repeating, then
|
||||
+ * this task was never executed.
|
||||
+ */
|
||||
+ CANCELLED,
|
||||
+
|
||||
+ /**
|
||||
+ * The task is repeating and currently executing, but future executions are cancelled and will not occur.
|
||||
+ */
|
||||
+ CANCELLED_RUNNING;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index ac9b690fcccb60b587e5345f12f1383afd0a73a1..4ae25cb199c6e20b51c4a1e7ac4ff55b23ae724f 100644
|
||||
index ac9b690fcccb60b587e5345f12f1383afd0a73a1..22952628c894e29bfdb94897bd9970103730b898 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -2459,6 +2459,35 @@ public final class Bukkit {
|
||||
@@ -2459,6 +2459,44 @@ public final class Bukkit {
|
||||
return server.getPotionBrewer();
|
||||
}
|
||||
// Paper end
|
||||
@ -144,6 +443,15 @@ index ac9b690fcccb60b587e5345f12f1383afd0a73a1..4ae25cb199c6e20b51c4a1e7ac4ff55b
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the async task scheduler. The async task scheduler can be used to schedule tasks
|
||||
+ * that execute asynchronously from the server tick process.
|
||||
+ * @return the async task scheduler
|
||||
+ */
|
||||
+ public static @NotNull io.papermc.paper.threadedregions.scheduler.AsyncScheduler getAsyncScheduler() {
|
||||
+ return server.getAsyncScheduler();
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the global region task scheduler. The global task scheduler can be used to schedule
|
||||
+ * tasks to execute on the global region.
|
||||
+ * <p>
|
||||
@ -160,10 +468,10 @@ index ac9b690fcccb60b587e5345f12f1383afd0a73a1..4ae25cb199c6e20b51c4a1e7ac4ff55b
|
||||
@NotNull
|
||||
public static Server.Spigot spigot() {
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 2204336d8800311b65e894739ab1b27273e7c6f2..1092ceef77bad421df647d349d997d02b2ba80a9 100644
|
||||
index 2204336d8800311b65e894739ab1b27273e7c6f2..ea4d93680066295de9fd447eda58b93014eac635 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -2139,4 +2139,29 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
@@ -2139,4 +2139,36 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
*/
|
||||
@NotNull org.bukkit.potion.PotionBrewer getPotionBrewer();
|
||||
// Paper end
|
||||
@ -179,7 +487,14 @@ index 2204336d8800311b65e894739ab1b27273e7c6f2..1092ceef77bad421df647d349d997d02
|
||||
+ * </p>
|
||||
+ * @return the region task scheduler
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.threadedregions.scheduler.RegionisedScheduler getRegionScheduler();
|
||||
+ public @NotNull io.papermc.paper.threadedregions.scheduler.RegionisedScheduler getRegionScheduler();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the async task scheduler. The async task scheduler can be used to schedule tasks
|
||||
+ * that execute asynchronously from the server tick process.
|
||||
+ * @return the async task scheduler
|
||||
+ */
|
||||
+ public @NotNull io.papermc.paper.threadedregions.scheduler.AsyncScheduler getAsyncScheduler();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the global region task scheduler. The global task scheduler can be used to schedule
|
||||
@ -212,15 +527,18 @@ index cdbc7329cf5f67d66e31eb31e83b9e7997040f72..90451ed12b2c95bb372ac2e3cbb57b8b
|
||||
+ // Folia end - region threading API
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
index b012ce40d82389c29d1b841ff685425ac10a7f9e..499dc8309a16b33d16b57b433c3c5b4330323717 100644
|
||||
index b012ce40d82389c29d1b841ff685425ac10a7f9e..057fa5dc78734520224af5031250b6be101ce3cb 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
@@ -585,7 +585,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||
@@ -585,9 +585,9 @@ public final class SimplePluginManager implements PluginManager {
|
||||
}
|
||||
|
||||
try {
|
||||
- server.getScheduler().cancelTasks(plugin);
|
||||
+ //server.getScheduler().cancelTasks(plugin); // Folia - Bukkit scheduler not supported
|
||||
+ server.getAsyncScheduler().cancelTasks(plugin); // Folia - new schedulers
|
||||
} catch (Throwable ex) {
|
||||
handlePluginException("Error occurred (in the plugin loader) while cancelling tasks for "
|
||||
- handlePluginException("Error occurred (in the plugin loader) while cancelling tasks for "
|
||||
+ handlePluginException("Error occurred (in the plugin loader) while cancelling async tasks for " // Folia - new schedulers
|
||||
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ index 0c9f4d1e9104fa6951114c1f9ec954dfcc749196..fc11577083672f127335613459436167
|
||||
|
||||
@NotNull
|
||||
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
index 499dc8309a16b33d16b57b433c3c5b4330323717..25f228e616d1f5475a06bf3eeb2cf1cf6b6ed352 100644
|
||||
index 057fa5dc78734520224af5031250b6be101ce3cb..ec838d1c7850f0d07980b051dff7c88db0aa6dbf 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
@@ -163,6 +163,12 @@ public final class SimplePluginManager implements PluginManager {
|
||||
|
@ -11,10 +11,10 @@ the schedulers depending on the result of the ownership
|
||||
check.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index 4ae25cb199c6e20b51c4a1e7ac4ff55b23ae724f..b8c62f431bf802a80fa097f1e5f8e6247badd0ea 100644
|
||||
index 22952628c894e29bfdb94897bd9970103730b898..62b7f94de5ffacd3919f9843e64a40f6f329fadd 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -2487,6 +2487,100 @@ public final class Bukkit {
|
||||
@@ -2496,6 +2496,100 @@ public final class Bukkit {
|
||||
public static @NotNull io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler getGlobalRegionScheduler() {
|
||||
return server.getGlobalRegionScheduler();
|
||||
}
|
||||
@ -116,10 +116,10 @@ index 4ae25cb199c6e20b51c4a1e7ac4ff55b23ae724f..b8c62f431bf802a80fa097f1e5f8e624
|
||||
|
||||
@NotNull
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 1092ceef77bad421df647d349d997d02b2ba80a9..3a17ccd041ca64c8ab0cd3edf4ce6fc1c6f2d459 100644
|
||||
index ea4d93680066295de9fd447eda58b93014eac635..78cd452e804310eb8ed954833f2b7431ad9101b0 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -2163,5 +2163,83 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
@@ -2170,5 +2170,83 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
* @return the global region scheduler
|
||||
*/
|
||||
public @NotNull io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler getGlobalRegionScheduler();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -86,6 +86,19 @@ index 58d39268a2608901a14696d36f3c59d8d6ac06e7..021177d19384ef898667b8a374cd3838
|
||||
// Spigot end
|
||||
if (this.passengers.size() == 1 && this.passengers.get(0) == entity) {
|
||||
this.passengers = ImmutableList.of();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 34dd05b737ee02200c5973ad21a600b2e2434d07..306cc8fe9a90091dadac6a9f2d984342ff798218 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -378,7 +378,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
public final boolean isOwnedByCurrentRegion(Entity entity) {
|
||||
- return io.papermc.paper.util.TickThread.isTickThreadFor(((org.bukkit.craftbukkit.entity.CraftEntity)entity).getHandle());
|
||||
+ return io.papermc.paper.util.TickThread.isTickThreadFor(((org.bukkit.craftbukkit.entity.CraftEntity)entity).getHandleRaw()); // Folia - add thread checks to getHandle
|
||||
}
|
||||
// Folia end - region threading API
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/AbstractProjectile.java b/src/main/java/org/bukkit/craftbukkit/entity/AbstractProjectile.java
|
||||
index 825fdc6162797ade8e76e1ca3a863ed5fb48f936..f812ad4a4d6c640c3f3f2d5766ee2b5882583cc5 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/AbstractProjectile.java
|
||||
|
@ -10,10 +10,10 @@ the impact from scaling the region threads, but is not a fix
|
||||
to the underlying issue.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 4a4b19ebd3fe743ca957d5ab307ef4dc0a1becec..1e3acf15dc6c055212baa39905b9ce8fa33d081a 100644
|
||||
index fb2f7cde13ef96334a42448798a4902e8c1e06a3..d43202f7de86e8d0c74abc0b7ff23baa69da7c87 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -2872,6 +2872,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -2873,6 +2873,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
public final void executeMidTickTasks() {
|
||||
|
@ -0,0 +1,74 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||||
Date: Wed, 22 Mar 2023 14:40:24 -0700
|
||||
Subject: [PATCH] Throw UnsupportedOperationException() for broken APIs
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 306cc8fe9a90091dadac6a9f2d984342ff798218..e149cec9deb1bd34c5a687ffed7f698c7f980875 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1266,6 +1266,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
public World createWorld(WorldCreator creator) {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
|
||||
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP");
|
||||
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
|
||||
Validate.notNull(creator, "Creator may not be null");
|
||||
@@ -1406,6 +1407,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
public boolean unloadWorld(World world, boolean save) {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not implemented properly yet
|
||||
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
|
||||
if (world == null) {
|
||||
return false;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
||||
index fe57437155ff9471738d3b85e787350601b79584..4ccdcdc78c86a698d555b6dc53bbd8668ca41d39 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
||||
@@ -44,6 +44,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
}
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) throws IllegalArgumentException {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
|
||||
if (displayName == null) {
|
||||
displayName = net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
@@ -212,6 +213,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
|
||||
@Override
|
||||
public Team registerNewTeam(String name) throws IllegalArgumentException {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
|
||||
Validate.notNull(name, "Team name cannot be null");
|
||||
Validate.isTrue(name.length() <= Short.MAX_VALUE, "Team name '" + name + "' is longer than the limit of 32767 characters");
|
||||
Validate.isTrue(this.board.getPlayerTeam(name) == null, "Team name '" + name + "' is already in use");
|
||||
@@ -239,6 +241,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
|
||||
@Override
|
||||
public void clearSlot(DisplaySlot slot) throws IllegalArgumentException {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
|
||||
Validate.notNull(slot, "Slot cannot be null");
|
||||
this.board.setDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot), null);
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
||||
index 138407c2d4b0bc55ddb9aac5d2aa3edadda090fb..071289fe33f444b903b61d6ec34c9ca4873c9ac5 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
||||
@@ -42,6 +42,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
|
||||
|
||||
@Override
|
||||
public CraftScoreboard getNewScoreboard() {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
|
||||
org.spigotmc.AsyncCatcher.catchOp("scoreboard creation"); // Spigot
|
||||
CraftScoreboard scoreboard = new CraftScoreboard(new ServerScoreboard(this.server));
|
||||
// Paper start
|
||||
@@ -68,6 +69,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
|
||||
|
||||
// CraftBukkit method
|
||||
public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard bukkitScoreboard) throws IllegalArgumentException {
|
||||
+ if (true) throw new UnsupportedOperationException(); // Folia - not supported yet
|
||||
Validate.isTrue(bukkitScoreboard instanceof CraftScoreboard, "Cannot set player scoreboard to an unregistered Scoreboard");
|
||||
|
||||
CraftScoreboard scoreboard = (CraftScoreboard) bukkitScoreboard;
|
Loading…
Reference in New Issue
Block a user