From a35fa83843daa00df508e88a5def5a01d6199e1f Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 23 Nov 2018 11:40:21 +1100 Subject: SPIGOT-4472: Add Consumer scheduler methods --- .../java/org/bukkit/scheduler/BukkitScheduler.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/scheduler/BukkitScheduler.java b/src/main/java/org/bukkit/scheduler/BukkitScheduler.java index 3e696ec5..abd0dffb 100644 --- a/src/main/java/org/bukkit/scheduler/BukkitScheduler.java +++ b/src/main/java/org/bukkit/scheduler/BukkitScheduler.java @@ -4,6 +4,7 @@ import org.bukkit.plugin.Plugin; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.List; +import java.util.function.Consumer; public interface BukkitScheduler { @@ -213,6 +214,16 @@ public interface BukkitScheduler { */ public BukkitTask runTask(Plugin plugin, Runnable task) throws IllegalArgumentException; + /** + * Returns a task that will run on the next server tick. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTask(Plugin plugin, Consumer task) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTask(Plugin)} * @@ -239,6 +250,19 @@ public interface BukkitScheduler { */ public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable task) throws IllegalArgumentException; + /** + * Asynchronous tasks should never access any API in Bukkit. Great care + * should be taken to assure the thread-safety of asynchronous tasks. + *

+ * Returns a task that will run asynchronously. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTaskAsynchronously(Plugin plugin, Consumer task) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTaskAsynchronously(Plugin)} * @param plugin the reference to the plugin scheduling task @@ -263,6 +287,18 @@ public interface BukkitScheduler { */ public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay) throws IllegalArgumentException; + /** + * Returns a task that will run after the specified number of server + * ticks. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @param delay the ticks to wait before running the task + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTaskLater(Plugin plugin, Consumer task, long delay) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTaskLater(Plugin, long)} * @param plugin the reference to the plugin scheduling task @@ -291,6 +327,21 @@ public interface BukkitScheduler { */ public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable task, long delay) throws IllegalArgumentException; + /** + * Asynchronous tasks should never access any API in Bukkit. Great care + * should be taken to assure the thread-safety of asynchronous tasks. + *

+ * Returns a task that will run asynchronously after the specified number + * of server ticks. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @param delay the ticks to wait before running the task + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTaskLaterAsynchronously(Plugin plugin, Consumer task, long delay) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTaskLaterAsynchronously(Plugin, long)} * @param plugin the reference to the plugin scheduling task @@ -317,6 +368,19 @@ public interface BukkitScheduler { */ public BukkitTask runTaskTimer(Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException; + /** + * Returns a task that will repeatedly run until cancelled, starting after + * the specified number of server ticks. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @param delay the ticks to wait before running the task + * @param period the ticks to wait between runs + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTaskTimer(Plugin plugin, Consumer task, long delay, long period) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTaskTimer(Plugin, long, long)} * @param plugin the reference to the plugin scheduling task @@ -348,6 +412,23 @@ public interface BukkitScheduler { */ public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException; + /** + * Asynchronous tasks should never access any API in Bukkit. Great care + * should be taken to assure the thread-safety of asynchronous tasks. + *

+ * Returns a task that will repeatedly run asynchronously until cancelled, + * starting after the specified number of server ticks. + * + * @param plugin the reference to the plugin scheduling task + * @param task the task to be run + * @param delay the ticks to wait before running the task for the first + * time + * @param period the ticks to wait between runs + * @throws IllegalArgumentException if plugin is null + * @throws IllegalArgumentException if task is null + */ + public void runTaskTimerAsynchronously(Plugin plugin, Consumer task, long delay, long period) throws IllegalArgumentException; + /** * @deprecated Use {@link BukkitRunnable#runTaskTimerAsynchronously(Plugin, long, long)} * @param plugin the reference to the plugin scheduling task -- cgit v1.2.3