Class ServerRunnable
java.lang.Object
net.vitacraft.serverlibraries.api.scheduling.ServerRunnable
- All Implemented Interfaces:
Runnable
This class is provided as an easy way to handle scheduling tasks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Attempts to cancel this task.int
Gets the task id for this runnable.boolean
Returns true if this task has been cancelled.@NotNull ServerSchedulerTask
runTask()
Schedules this in the ServerLibrariesAPI scheduler to run on next tick.@NotNull ServerSchedulerTask
Asynchronous tasks should never access any API in ServerLibrariesAPI.@NotNull ServerSchedulerTask
runTaskLater
(long delay) Schedules this to run after the specified number of server ticks.@NotNull ServerSchedulerTask
runTaskLaterAsynchronously
(long delay) Asynchronous tasks should never access any API in ServerLibrariesAPI.@NotNull ServerSchedulerTask
runTaskTimer
(long delay, long period) Schedules this to repeatedly run until cancelled, starting after the specified number of server ticks.@NotNull ServerSchedulerTask
runTaskTimerAsynchronously
(long delay, long period) Asynchronous tasks should never access any API in ServerLibrariesAPI.
-
Constructor Details
-
ServerRunnable
public ServerRunnable()
-
-
Method Details
-
isCancelled
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
Attempts to cancel this task.- Throws:
IllegalStateException
- if task was not scheduled yet
-
runTask
@NotNull public @NotNull ServerSchedulerTask runTask() throws IllegalArgumentException, IllegalStateExceptionSchedules this in the ServerLibrariesAPI scheduler to run on next tick.- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
runTaskAsynchronously
@NotNull public @NotNull ServerSchedulerTask runTaskAsynchronously() throws IllegalArgumentException, IllegalStateExceptionAsynchronous tasks should never access any API in ServerLibrariesAPI. Great care should be taken to assure the thread-safety of asynchronous tasks.Schedules this in the ServerLibrariesAPI scheduler to run asynchronously.
- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
runTaskLater
@NotNull public @NotNull ServerSchedulerTask runTaskLater(long delay) throws IllegalArgumentException, IllegalStateException Schedules this to run after the specified number of server ticks.- Parameters:
delay
- the ticks to wait before running the task- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
runTaskLaterAsynchronously
@NotNull public @NotNull ServerSchedulerTask runTaskLaterAsynchronously(long delay) throws IllegalArgumentException, IllegalStateException Asynchronous tasks should never access any API in ServerLibrariesAPI. 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:
delay
- the ticks to wait before running the task- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
runTaskTimer
@NotNull public @NotNull ServerSchedulerTask runTaskTimer(long delay, long period) throws IllegalArgumentException, IllegalStateException Schedules this to repeatedly run until cancelled, starting after the specified number of server ticks.- Parameters:
delay
- the ticks to wait before running the taskperiod
- the ticks to wait between runs- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
runTaskTimerAsynchronously
@NotNull public @NotNull ServerSchedulerTask runTaskTimerAsynchronously(long delay, long period) throws IllegalArgumentException, IllegalStateException Asynchronous tasks should never access any API in ServerLibrariesAPI. 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:
delay
- the ticks to wait before running the task for the first timeperiod
- the ticks to wait between runs- Returns:
- a ServerSchedulerTask that contains the id number
- Throws:
IllegalArgumentException
- if plugin is nullIllegalStateException
- if this was already scheduled
-
getTaskId
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
-