Class Task

java.lang.Object
org.bukkit.scheduler.BukkitRunnable
me.totalfreedom.service.Task
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
BossBarTimer, ReactionTask

public abstract class Task extends org.bukkit.scheduler.BukkitRunnable
Represents a task that can be run asynchronously or synchronously.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Task(String name)
    Creates a new task with the given name.
    protected
    Task(String name, long delay)
    Creates a new task with the given name and delay.
    protected
    Task(String name, long delay, long interval)
    Creates a new task with the given name, delay, and interval.
    protected
    Task(String name, long delay, Duration interval)
    Creates a new task with the given name, delay, and interval.
    protected
    Task(String name, Duration delay)
    Creates a new task with the given name and delay.
    protected
    Task(String name, Duration delay, Duration interval)
    Creates a new task with the given name, delay, and interval.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    long
     
     
    boolean
     
    boolean
     
    boolean
     

    Methods inherited from class org.bukkit.scheduler.BukkitRunnable

    cancel, getTaskId, isCancelled, runTask, runTaskAsynchronously, runTaskLater, runTaskLaterAsynchronously, runTaskTimer, runTaskTimerAsynchronously

    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

      protected Task(String name)
      Creates a new task with the given name. This will initialize a task with no initail delay and no interval.
      Parameters:
      name - The name of the task.
    • Task

      protected Task(String name, long delay, long interval)
      Creates a new task with the given name, delay, and interval.
      It's important to note that the delay and interval are in ticks. One tick is equal to 1/20th of a second, which means there are 20 ticks are in one second. If your interval is intended to be anything less than 20 ticks, you should use a Service instead.
      Parameters:
      name - The name of the task.
      delay - The delay of the task.
      interval - The interval of the task.
    • Task

      protected Task(String name, long delay)
      Creates a new task with the given name and delay. This will intialize a single execute task with an initial delay before execution.
      Parameters:
      name - The name of the task.
      delay - How long the task should wait before executing.
    • Task

      protected Task(String name, Duration delay)
      Creates a new task with the given name and delay. This is the same as longs, except that here, we naturally support durations which are automatically converted to ticks for you. This means that using Duration.ofSeconds(long) will work as expected.
      Parameters:
      name - The name of the task.
      delay - How long the task should wait before executing.
    • Task

      protected Task(String name, Duration delay, Duration interval)
      Creates a new task with the given name, delay, and interval. This is the same as longs, except that here, we naturally support durations which are automatically converted to ticks for you. This means that using Duration.ofSeconds(long) will work as expected.
      Parameters:
      name - The name of the task.
      delay - How long the task should wait before executing.
      interval - How long the task should wait between executions.
    • Task

      protected Task(String name, long delay, Duration interval)
      Creates a new task with the given name, delay, and interval. This method is a convenience method to use a Duration for the interval, while also being able to specify the delay as -1L so the task does not have an initial delay before execution.
      Parameters:
      name - The name of the task.
      delay - The delay of the task.
      interval - The interval of the task.
  • Method Details

    • isRunning

      public boolean isRunning()
      Returns:
      True if the task is running, false otherwise.
    • getName

      public String getName()
      Returns:
      The name of the task.
    • isRepeating

      public boolean isRepeating()
      Returns:
      True if the task is repeating, false otherwise.
    • isDelayed

      public boolean isDelayed()
      Returns:
      True if the task is delayed, false otherwise.
    • getInterval

      public long getInterval()
      Returns:
      The interval between each task execution.
    • getDelay

      public long getDelay()
      Returns:
      The initial delay before the first execution of this task.