Class Task

java.lang.Object
ch.njol.skript.util.Task
All Implemented Interfaces:
Closeable, Runnable

public abstract class Task extends Object implements Runnable, Closeable
  • Constructor Summary

    Constructors
    Constructor
    Description
    Task(org.bukkit.plugin.Plugin plugin, long delay)
     
    Task(org.bukkit.plugin.Plugin plugin, long delay, boolean async)
     
    Task(org.bukkit.plugin.Plugin plugin, long delay, long period)
     
    Task(org.bukkit.plugin.Plugin plugin, long delay, long period, boolean async)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    Equivalent to callSync(c, Skript.getInstance())
    static <T> T
    callSync(Callable<T> c, org.bukkit.plugin.Plugin p)
    Calls a method on Bukkit's main thread.
    final void
    Cancels this task.
    void
    Closes this object.
    final boolean
     
    void
    setNextExecution(long delay)
    Re-schedules the task to run next after the given delay.
    void
    setPeriod(long period)
    Sets the period of this task.

    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

    • Task

      public Task(org.bukkit.plugin.Plugin plugin, long delay, long period)
    • Task

      public Task(org.bukkit.plugin.Plugin plugin, long delay, long period, boolean async)
    • Task

      public Task(org.bukkit.plugin.Plugin plugin, long delay)
    • Task

      public Task(org.bukkit.plugin.Plugin plugin, long delay, boolean async)
  • 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: Closeable
      Closes 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:
      close in interface Closeable
    • 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

      @Nullable public static <T> T callSync(Callable<T> c)
      Equivalent to callSync(c, Skript.getInstance())
    • callSync

      @Nullable public static <T> T callSync(Callable<T> c, org.bukkit.plugin.Plugin p)
      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 method
      p - 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)