Package org.bukkit.scheduler
Class BukkitRunnable
java.lang.Object
org.bukkit.scheduler.BukkitRunnable
- All Implemented Interfaces:
java.lang.Runnable
public abstract class BukkitRunnable
extends java.lang.Object
implements java.lang.Runnable
This class is provided as an easy way to handle scheduling tasks.
-
Constructor Summary
Constructors Constructor Description BukkitRunnable()
-
Method Summary
Modifier and Type Method Description void
cancel()
Attempts to cancel this task.int
getTaskId()
Gets the task id for this runnable.BukkitTask
runTask(Plugin plugin)
Schedules this in the Bukkit scheduler to run on next tick.BukkitTask
runTaskAsynchronously(Plugin plugin)
Asynchronous tasks should never access any API in Bukkit.BukkitTask
runTaskLater(Plugin plugin, long delay)
Schedules this to run after the specified number of server ticks.BukkitTask
runTaskLaterAsynchronously(Plugin plugin, long delay)
Asynchronous tasks should never access any API in Bukkit.BukkitTask
runTaskTimer(Plugin plugin, long delay, long period)
Schedules this to repeatedly run until cancelled, starting after the specified number of server ticks.BukkitTask
runTaskTimerAsynchronously(Plugin plugin, long delay, long period)
Asynchronous tasks should never access any API in Bukkit.
-
Constructor Details
-
BukkitRunnable
public BukkitRunnable()
-
-
Method Details
-
cancel
public void cancel() throws java.lang.IllegalStateExceptionAttempts to cancel this task.- Throws:
java.lang.IllegalStateException
- if task was not scheduled yet
-
runTask
public BukkitTask runTask(Plugin plugin) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionSchedules this in the Bukkit scheduler to run on next tick.- Parameters:
plugin
- the reference to the plugin scheduling task- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTask(Plugin, Runnable)
-
runTaskAsynchronously
public BukkitTask runTaskAsynchronously(Plugin plugin) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionAsynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.Schedules this in the Bukkit scheduler to run asynchronously.
- Parameters:
plugin
- the reference to the plugin scheduling task- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTaskAsynchronously(Plugin, Runnable)
-
runTaskLater
public BukkitTask runTaskLater(Plugin plugin, long delay) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionSchedules this to run after the specified number of server ticks.- Parameters:
plugin
- the reference to the plugin scheduling taskdelay
- the ticks to wait before running the task- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTaskLater(Plugin, Runnable, long)
-
runTaskLaterAsynchronously
public BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionAsynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.Schedules this to run asynchronously after the specified number of server ticks.
- Parameters:
plugin
- the reference to the plugin scheduling taskdelay
- the ticks to wait before running the task- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTaskLaterAsynchronously(Plugin, Runnable, long)
-
runTaskTimer
public BukkitTask runTaskTimer(Plugin plugin, long delay, long period) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionSchedules this to repeatedly run until cancelled, starting after the specified number of server ticks.- Parameters:
plugin
- the reference to the plugin scheduling taskdelay
- the ticks to wait before running the taskperiod
- the ticks to wait between runs- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTaskTimer(Plugin, Runnable, long, long)
-
runTaskTimerAsynchronously
public BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws java.lang.IllegalArgumentException, java.lang.IllegalStateExceptionAsynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.Schedules this to repeatedly run asynchronously until cancelled, starting after the specified number of server ticks.
- Parameters:
plugin
- the reference to the plugin scheduling taskdelay
- the ticks to wait before running the task for the first timeperiod
- the ticks to wait between runs- Returns:
- a BukkitTask that contains the id number
- Throws:
java.lang.IllegalArgumentException
- if plugin is nulljava.lang.IllegalStateException
- if this was already scheduled- See Also:
BukkitScheduler.runTaskTimerAsynchronously(Plugin, Runnable, long, long)
-
getTaskId
public int getTaskId() throws java.lang.IllegalStateExceptionGets the task id for this runnable.- Returns:
- the task id that this runnable was scheduled as
- Throws:
java.lang.IllegalStateException
- if task was not scheduled yet
-