Package org.bukkit.scheduler

# Class BukkitRunnable

java.lang.Object
org.bukkit.scheduler.BukkitRunnable

All Implemented Interfaces:
  `Runnable`

public abstract class BukkitRunnable extends Object implements 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.
`boolean`
`isCancelled()`
Returns true if this task has been cancelled.
`@NotNull BukkitTask`
`runTask(@NotNull Plugin plugin)`
Schedules this in the Bukkit scheduler to run on next tick.
`@NotNull BukkitTask`
`runTaskAsynchronously(@NotNull Plugin plugin)`
Asynchronous tasks should never access any API in Bukkit.
`@NotNull BukkitTask`
`runTaskLater(@NotNull Plugin plugin, long delay)`
Schedules this to run after the specified number of server ticks.
`@NotNull BukkitTask`
`runTaskLaterAsynchronously(@NotNull Plugin plugin, long delay)`
Asynchronous tasks should never access any API in Bukkit.
`@NotNull BukkitTask`
`runTaskTimer(@NotNull Plugin plugin, long delay, long period)`
Schedules this to repeatedly run until cancelled, starting after the specified number of server ticks.
`@NotNull BukkitTask`
`runTaskTimerAsynchronously(@NotNull Plugin plugin, long delay, long period)`
Asynchronous tasks should never access any API in Bukkit.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.lang.Runnable

`run`

## Constructor Details

### BukkitRunnable

public BukkitRunnable()

## Method Details

### isCancelled

public boolean isCancelled() throws IllegalStateException
Returns true if this task has been cancelled.

Returns:
  true if the task has been cancelled
Throws:
  `IllegalStateException` - if task was not scheduled yet

### cancel

public void cancel() throws IllegalStateException
Attempts to cancel this task.

Throws:
  `IllegalStateException` - if task was not scheduled yet

### runTask

@NotNull public @NotNull BukkitTask runTask(@NotNull @NotNull Plugin plugin) throws IllegalArgumentException, IllegalStateException
Schedules 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:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTask(Plugin, Runnable)`

### runTaskAsynchronously

@NotNull public @NotNull BukkitTask runTaskAsynchronously(@NotNull @NotNull Plugin plugin) throws IllegalArgumentException, IllegalStateException
Asynchronous 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:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTaskAsynchronously(Plugin, Runnable)`

### runTaskLater

@NotNull public @NotNull BukkitTask runTaskLater(@NotNull @NotNull Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException
Schedules this to run after the specified number of server ticks.

Parameters:
  `plugin` - the reference to the plugin scheduling task
  `delay` - the ticks to wait before running the task
Returns:
  a BukkitTask that contains the id number
Throws:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTaskLater(Plugin, Runnable, long)`

### runTaskLaterAsynchronously

@NotNull public @NotNull BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException
Asynchronous 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 task
  `delay` - the ticks to wait before running the task
Returns:
  a BukkitTask that contains the id number
Throws:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTaskLaterAsynchronously(Plugin, Runnable, long)`

### runTaskTimer

@NotNull public @NotNull BukkitTask runTaskTimer(@NotNull @NotNull Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException
Schedules this to repeatedly run until cancelled, starting after the specified number of server ticks.

Parameters:
  `plugin` - the reference to the plugin scheduling task
  `delay` - the ticks to wait before running the task
  `period` - the ticks to wait between runs
Returns:
  a BukkitTask that contains the id number
Throws:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTaskTimer(Plugin, Runnable, long, long)`

### runTaskTimerAsynchronously

@NotNull public @NotNull BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException
Asynchronous 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 task
  `delay` - the ticks to wait before running the task for the first time
  `period` - the ticks to wait between runs
Returns:
  a BukkitTask that contains the id number
Throws:
  `IllegalArgumentException` - if plugin is null
  `IllegalStateException` - if this was already scheduled
See Also:
  - `BukkitScheduler.runTaskTimerAsynchronously(Plugin, Runnable, long, long)`

### getTaskId

public int getTaskId() throws IllegalStateException
Gets the task id for this runnable.

Returns:
  the task id that this runnable was scheduled as
Throws:
  `IllegalStateException` - if task was not scheduled yet