Class BukkitFoliaScheduler

java.lang.Object
io.artificial.enchantments.internal.BukkitFoliaScheduler
All Implemented Interfaces:
FoliaScheduler

public final class BukkitFoliaScheduler extends Object implements FoliaScheduler
FoliaLib-backed implementation of FoliaScheduler.

On Folia this delegates to region/entity/global schedulers through FoliaLib. On Paper/Purpur it resolves to the normal main-thread scheduler.

  • Constructor Details

    • BukkitFoliaScheduler

      public BukkitFoliaScheduler(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Creates a new Bukkit folia scheduler.
      Parameters:
      plugin - the owning plugin
  • Method Details

    • runGlobal

      public void runGlobal(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task)
      Executes a task on the global region thread.
      Specified by:
      runGlobal in interface FoliaScheduler
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
    • runAtLocation

      public void runAtLocation(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task)
      Executes a task on the region thread for the given location.
      Specified by:
      runAtLocation in interface FoliaScheduler
      Parameters:
      plugin - the plugin scheduling the task
      location - the location determining which region thread
      task - the task to execute
    • runAtEntity

      public void runAtEntity(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task)
      Executes a task on the entity's scheduler.
      Specified by:
      runAtEntity in interface FoliaScheduler
      Parameters:
      plugin - the plugin scheduling the task
      entity - the entity to schedule the task for
      task - the task to execute
    • runGlobalDelayed

      @NotNull public @NotNull FoliaScheduler.ScheduledTask runGlobalDelayed(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delayTicks)
      Schedules a delayed task on the global region thread.
      Specified by:
      runGlobalDelayed in interface FoliaScheduler
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
      delayTicks - the delay in ticks
      Returns:
      a task handle that can be used to cancel the task
    • runGlobalTimer

      @NotNull public @NotNull FoliaScheduler.ScheduledTask runGlobalTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<FoliaScheduler.ScheduledTask> task, long delayTicks, long periodTicks)
      Schedules a repeating task on the global region thread.
      Specified by:
      runGlobalTimer in interface FoliaScheduler
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
      delayTicks - the initial delay in ticks
      periodTicks - the period between executions in ticks
      Returns:
      a task handle that can be used to cancel the task
    • isPrimaryThread

      public boolean isPrimaryThread()
      Returns true if the current thread is the primary server thread.
      Specified by:
      isPrimaryThread in interface FoliaScheduler
      Returns:
      true if on main thread