Package ch.njol.skript.util
Class Task
java.lang.Object
ch.njol.skript.util.Task
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
-
Constructor Summary
ConstructorsConstructorDescriptionTask(org.bukkit.plugin.Plugin plugin, boolean useScriptLoaderExecutor) Creates a new task that will run optionally on the script loader executor.Task(org.bukkit.plugin.Plugin plugin, boolean useScriptLoaderExecutor, long delay) Creates a new task that will run optionally on the script loader executor and after a delay.Task(org.bukkit.plugin.Plugin plugin, long delay) Creates a new task that will run after the given delay.Task(org.bukkit.plugin.Plugin plugin, long delay, boolean async) Creates a new task that will run after the given delay and optionally asynchronously.Task(org.bukkit.plugin.Plugin plugin, long delay, long period) Creates a new task that will run after the given delay and then repeat every period ticks.Task(org.bukkit.plugin.Plugin plugin, long delay, long period, boolean async) Creates a new task that will run after the given delay and then repeat every period ticks optionally asyncronously. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TEquivalent tocallSync(c,Skript.getInstance())static <T> TCalls a method on Bukkit's main thread.final voidcancel()Cancels this task.voidclose()Closes this object.final booleanisAlive()voidsetNextExecution(long delay) Re-schedules the task to run next after the given delay.voidsetPeriod(long period) Sets the period of this task.
-
Constructor Details
-
Task
public Task(org.bukkit.plugin.Plugin plugin, long delay, long period) Creates a new task that will run after the given delay and then repeat every period ticks.- Parameters:
plugin- The plugin that owns this task.delay- Delay in ticks before the task is run for the first time.period- Period in ticks between subsequent executions of the task.
-
Task
public Task(org.bukkit.plugin.Plugin plugin, long delay, long period, boolean async) Creates a new task that will run after the given delay and then repeat every period ticks optionally asyncronously.- Parameters:
plugin- The plugin that owns this task.delay- Delay in ticks before the task is run for the first time.period- Period in ticks between subsequent executions of the task.async- Whether to run the task asynchronously
-
Task
public Task(org.bukkit.plugin.Plugin plugin, long delay) Creates a new task that will run after the given delay.- Parameters:
plugin- The plugin that owns this task.delay- Delay in ticks before the task is run for the first time.
-
Task
public Task(org.bukkit.plugin.Plugin plugin, boolean useScriptLoaderExecutor) Creates a new task that will run optionally on the script loader executor.- Parameters:
plugin- The plugin that owns this task.useScriptLoaderExecutor- Whether to use the script loader executor. Setting is based on the config.sk user setting.
-
Task
public Task(org.bukkit.plugin.Plugin plugin, long delay, boolean async) Creates a new task that will run after the given delay and optionally asynchronously.- Parameters:
plugin- The plugin that owns this task.delay- Delay in ticks before the task is run for the first time.async- Whether to run the task asynchronously
-
Task
public Task(org.bukkit.plugin.Plugin plugin, boolean useScriptLoaderExecutor, long delay) Creates a new task that will run optionally on the script loader executor and after a delay.- Parameters:
plugin- The plugin that owns this task.useScriptLoaderExecutor- Whether to use the script loader executor. Setting is based on the config.sk user setting.delay- Delay in ticks before the task is run for the first time.
-
-
Method Details
-
isAlive
public final boolean isAlive()- Returns:
- Whether this task is still running, i.e. whether it will run later or is currently running.
-
cancel
public final void cancel()Cancels this task. -
close
public void close()Description copied from interface:CloseableCloses this object. This method may be called multiple times and may or may not have an effect on subsequent calls (e.g. a task might be stopped, but resumed later and stopped again).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
setNextExecution
public void setNextExecution(long delay) Re-schedules the task to run next after the given delay. If this task was repeating it will continue so using the same period as before.- Parameters:
delay-
-
setPeriod
public void setPeriod(long period) Sets the period of this task. This will re-schedule the task to be run next after the given period if the task is still running.- Parameters:
period- Period in ticks or -1 to cancel the task and make it non-repeating
-
callSync
Equivalent tocallSync(c,Skript.getInstance()) -
callSync
Calls a method on Bukkit's main thread.Hint: Use a Callable<Void> to make a task which blocks your current thread until it is completed.
- Parameters:
c- The methodp- The plugin that owns the task. Must be enabled.- Returns:
- What the method returned or null if it threw an error or was stopped (usually due to the server shutting down)
-