Class FoliaScheduler

java.lang.Object
me.tamkungz.signals.folia.FoliaScheduler

public final class FoliaScheduler extends Object
Small wrapper over the Folia schedulers for one plugin.

On Folia every region ticks on its own thread, so code that touches a block, chunk or entity must run on the thread that owns it. The methods here pick the matching scheduler; ownsRegion(Location), ownsEntity(Entity) and isGlobalThread() tell whether the current thread already is that thread. Outside Folia, Paper runs the same schedulers on the main thread.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FoliaScheduler(org.bukkit.plugin.Plugin plugin)
    Creates a scheduler for a plugin.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Runs a task right away on a thread that is not tied to any region.
    boolean
    entity(org.bukkit.entity.Entity entity, Runnable task, Runnable retired)
    Runs a task on the next tick of the region that owns an entity, following the entity if it moves.
    void
    Runs a task on the next tick of the global region.
    static boolean
    Tells whether the server is Folia.
    boolean
    Tells whether the current thread is the global region thread (the main thread outside Folia).
    boolean
    ownsEntity(org.bukkit.entity.Entity entity)
    Tells whether the current thread owns an entity.
    boolean
    ownsRegion(org.bukkit.Location location)
    Tells whether the current thread owns the region around a location.
    org.bukkit.plugin.Plugin
    Returns the plugin that owns the scheduled tasks.
    void
    region(org.bukkit.Location location, Runnable task)
    Runs a task on the next tick of the region that owns a location.
    void
    region(org.bukkit.World world, int chunkX, int chunkZ, Runnable task)
    Runs a task on the next tick of the region that owns a chunk.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FoliaScheduler

      public FoliaScheduler(org.bukkit.plugin.Plugin plugin)
      Creates a scheduler for a plugin.
      Parameters:
      plugin - plugin that owns the scheduled tasks
  • Method Details

    • isFolia

      public static boolean isFolia()
      Tells whether the server is Folia.
      Returns:
      true when regionised multithreading is active
    • plugin

      public org.bukkit.plugin.Plugin plugin()
      Returns the plugin that owns the scheduled tasks.
      Returns:
      the owning plugin
    • isGlobalThread

      public boolean isGlobalThread()
      Tells whether the current thread is the global region thread (the main thread outside Folia). Returns false on a Folia build that does not expose the check, so callers schedule instead.
      Returns:
      true on the global tick thread
    • ownsRegion

      public boolean ownsRegion(org.bukkit.Location location)
      Tells whether the current thread owns the region around a location.
      Parameters:
      location - location to check
      Returns:
      true if the current region owns it
    • ownsEntity

      public boolean ownsEntity(org.bukkit.entity.Entity entity)
      Tells whether the current thread owns an entity.
      Parameters:
      entity - entity to check
      Returns:
      true if the current region owns it
    • global

      public void global(Runnable task)
      Runs a task on the next tick of the global region.
      Parameters:
      task - task to run
    • region

      public void region(org.bukkit.Location location, Runnable task)
      Runs a task on the next tick of the region that owns a location.
      Parameters:
      location - location whose region runs the task
      task - task to run
    • region

      public void region(org.bukkit.World world, int chunkX, int chunkZ, Runnable task)
      Runs a task on the next tick of the region that owns a chunk.
      Parameters:
      world - world of the chunk
      chunkX - chunk X coordinate
      chunkZ - chunk Z coordinate
      task - task to run
    • entity

      public boolean entity(org.bukkit.entity.Entity entity, Runnable task, Runnable retired)
      Runs a task on the next tick of the region that owns an entity, following the entity if it moves.
      Parameters:
      entity - entity whose region runs the task
      task - task to run
      retired - called instead of task if the entity was removed first, may be null
      Returns:
      false if the entity was already removed and the task was not scheduled
    • async

      public void async(Runnable task)
      Runs a task right away on a thread that is not tied to any region.
      Parameters:
      task - task to run