Interface Scheduler


@NonExtendable public interface Scheduler
Runs code on the thread that owns what it touches (D35), on Paper and Folia alike: on Paper every thread below is the main thread, on Folia it is the global region, the region owning a location, or the region owning an entity. Get one with MachineEngine.scheduler(plugin): its tasks belong to that plugin and stop when it is disabled.

Delays and periods are in ticks; anything below 1 counts as 1. Once the server is stopping, nothing is scheduled (such a task would never run): run does nothing, runLater and runTimer return a cancelled task, and the entity variants return false or null.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    boolean
    isOwnedByCurrentThread(@NotNull org.bukkit.Location location)
     
    boolean
    isOwnedByCurrentThread(@NotNull org.bukkit.World world, int chunkX, int chunkZ)
     
    boolean
    isOwnedByCurrentThread(@NotNull org.bukkit.entity.Entity entity)
     
    void
    run(@NotNull Runnable task)
    Runs task on the next tick.
    void
    run(@NotNull org.bukkit.Location location, @NotNull Runnable task)
    Runs task on the next tick of the region owning location.
    void
    run(@NotNull org.bukkit.World world, int chunkX, int chunkZ, @NotNull Runnable task)
    Runs task on the next tick of the region owning the chunk.
    boolean
    run(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired)
    Runs task on the next tick of the region owning entity.
    void
    runAsync(@NotNull Runnable task)
    Runs task on a pooled thread.
    @NotNull Task
    runLater(@NotNull Runnable task, long delay)
     
    @NotNull Task
    runLater(@NotNull org.bukkit.Location location, @NotNull Runnable task, long delay)
     
    @NotNull Task
    runLater(@NotNull org.bukkit.World world, int chunkX, int chunkZ, @NotNull Runnable task, long delay)
     
    @Nullable Task
    runLater(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired, long delay)
    @NotNull Task
    runTimer(@NotNull Runnable task, long delay, long period)
     
    @NotNull Task
    runTimer(@NotNull org.bukkit.Location location, @NotNull Runnable task, long delay, long period)
     
    @Nullable Task
    runTimer(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired, long delay, long period)
    Runs task every period until cancelled or the entity is removed; then retired runs.
  • Method Details

    • isFolia

      boolean isFolia()
      Returns:
      whether the server is Folia (regions on several threads)
    • run

      void run(@NotNull @NotNull Runnable task)
      Runs task on the next tick.
    • runLater

      @NotNull @NotNull Task runLater(@NotNull @NotNull Runnable task, long delay)
    • runTimer

      @NotNull @NotNull Task runTimer(@NotNull @NotNull Runnable task, long delay, long period)
    • run

      void run(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task)
      Runs task on the next tick of the region owning location.
    • run

      void run(@NotNull @NotNull org.bukkit.World world, int chunkX, int chunkZ, @NotNull @NotNull Runnable task)
      Runs task on the next tick of the region owning the chunk.
    • runLater

      @NotNull @NotNull Task runLater(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task, long delay)
    • runLater

      @NotNull @NotNull Task runLater(@NotNull @NotNull org.bukkit.World world, int chunkX, int chunkZ, @NotNull @NotNull Runnable task, long delay)
    • runTimer

      @NotNull @NotNull Task runTimer(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task, long delay, long period)
    • run

      boolean run(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired)
      Runs task on the next tick of the region owning entity. If the entity is removed first, retired runs instead (on the entity's last thread, or at once).
      Returns:
      false, and nothing is scheduled, if the entity is no longer valid (a player who left)
    • runLater

      @Nullable @Nullable Task runLater(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired, long delay)
      Returns:
      the task, or null, and nothing is scheduled, if the entity is no longer valid
    • runTimer

      @Nullable @Nullable Task runTimer(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired, long delay, long period)
      Runs task every period until cancelled or the entity is removed; then retired runs.
      Returns:
      the task, or null, and nothing is scheduled, if the entity is no longer valid
    • runAsync

      void runAsync(@NotNull @NotNull Runnable task)
      Runs task on a pooled thread. It must not touch worlds, entities or players.
    • isOwnedByCurrentThread

      boolean isOwnedByCurrentThread(@NotNull @NotNull org.bukkit.Location location)
      Returns:
      whether the current thread may touch location (Paper: the main thread)
    • isOwnedByCurrentThread

      boolean isOwnedByCurrentThread(@NotNull @NotNull org.bukkit.World world, int chunkX, int chunkZ)
      Returns:
      whether the current thread may touch the chunk (Paper: the main thread)
    • isOwnedByCurrentThread

      boolean isOwnedByCurrentThread(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Returns:
      whether the current thread may touch entity (Paper: the main thread)