Class GlowScheduler

java.lang.Object
net.glowstone.scheduler.GlowScheduler
All Implemented Interfaces:
org.bukkit.scheduler.BukkitScheduler

public final class GlowScheduler extends Object implements org.bukkit.scheduler.BukkitScheduler
A scheduler for managing server ticks, Bukkit tasks, and other synchronization.
  • Constructor Details

    • GlowScheduler

      public GlowScheduler(GlowServer server, WorldScheduler worlds)
      Creates a new task scheduler.
      Parameters:
      server - The server that will use this scheduler.
      worlds - The WorldScheduler this scheduler will use for ticking the server's worlds.
    • GlowScheduler

      public GlowScheduler(org.bukkit.Server server, WorldScheduler worlds, SessionRegistry sessionRegistry)
      Creates a new task scheduler.
      Parameters:
      server - The server that will use this scheduler.
      worlds - The WorldScheduler this scheduler will use for ticking the server's worlds.
      sessionRegistry - The SessionRegistry this scheduler will use to tick players
  • Method Details

    • start

      public void start()
      Starts running ticks.
    • stop

      public void stop()
      Stops the scheduler and all tasks.
    • isPrimaryThread

      public boolean isPrimaryThread()
      Checks if the current Thread is the server's primary thread.
      Returns:
      If the current Thread is the server's primary thread.
    • scheduleInTickExecution

      public void scheduleInTickExecution(Runnable run)
      Schedules the given task for the start of the next tick.
      Parameters:
      run - the task to run
    • scheduleSyncDelayedTask

      public int scheduleSyncDelayedTask(org.bukkit.plugin.Plugin plugin, Runnable task)
      Specified by:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncDelayedTask

      public int scheduleSyncDelayedTask(org.bukkit.plugin.Plugin plugin, Runnable task, long delay)
      Specified by:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncDelayedTask

      @Deprecated public int scheduleSyncDelayedTask(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task)
      Deprecated.
      Specified by:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncDelayedTask

      @Deprecated public int scheduleSyncDelayedTask(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay)
      Deprecated.
      Specified by:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncRepeatingTask

      public int scheduleSyncRepeatingTask(org.bukkit.plugin.Plugin plugin, Runnable task, long delay, long period)
      Specified by:
      scheduleSyncRepeatingTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncRepeatingTask

      @Deprecated public int scheduleSyncRepeatingTask(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay, long period)
      Deprecated.
      Specified by:
      scheduleSyncRepeatingTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleAsyncDelayedTask

      @Deprecated public int scheduleAsyncDelayedTask(org.bukkit.plugin.Plugin plugin, Runnable task, long delay)
      Deprecated.
      Specified by:
      scheduleAsyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleAsyncDelayedTask

      @Deprecated public int scheduleAsyncDelayedTask(org.bukkit.plugin.Plugin plugin, Runnable task)
      Deprecated.
      Specified by:
      scheduleAsyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleAsyncRepeatingTask

      @Deprecated public int scheduleAsyncRepeatingTask(org.bukkit.plugin.Plugin plugin, Runnable task, long delay, long period)
      Deprecated.
      Specified by:
      scheduleAsyncRepeatingTask in interface org.bukkit.scheduler.BukkitScheduler
    • runTask

      public org.bukkit.scheduler.BukkitTask runTask(org.bukkit.plugin.Plugin plugin, Runnable task) throws IllegalArgumentException
      Specified by:
      runTask in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTask

      public void runTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task) throws IllegalArgumentException
      Specified by:
      runTask in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTask

      @Deprecated public org.bukkit.scheduler.BukkitTask runTask(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTask in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskAsynchronously

      public org.bukkit.scheduler.BukkitTask runTaskAsynchronously(org.bukkit.plugin.Plugin plugin, Runnable task) throws IllegalArgumentException
      Specified by:
      runTaskAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskAsynchronously

      public void runTaskAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task) throws IllegalArgumentException
      Specified by:
      runTaskAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskAsynchronously

      @Deprecated public org.bukkit.scheduler.BukkitTask runTaskAsynchronously(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTaskAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLater

      public org.bukkit.scheduler.BukkitTask runTaskLater(org.bukkit.plugin.Plugin plugin, Runnable task, long delay) throws IllegalArgumentException
      Specified by:
      runTaskLater in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLater

      public void runTaskLater(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task, long delay) throws IllegalArgumentException
      Specified by:
      runTaskLater in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLater

      @Deprecated public org.bukkit.scheduler.BukkitTask runTaskLater(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTaskLater in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLaterAsynchronously

      public org.bukkit.scheduler.BukkitTask runTaskLaterAsynchronously(org.bukkit.plugin.Plugin plugin, Runnable task, long delay) throws IllegalArgumentException
      Specified by:
      runTaskLaterAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLaterAsynchronously

      public void runTaskLaterAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task, long delay) throws IllegalArgumentException
      Specified by:
      runTaskLaterAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskLaterAsynchronously

      @Deprecated public org.bukkit.scheduler.BukkitTask runTaskLaterAsynchronously(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTaskLaterAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimer

      public org.bukkit.scheduler.BukkitTask runTaskTimer(org.bukkit.plugin.Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException
      Specified by:
      runTaskTimer in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimer

      public void runTaskTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task, long delay, long period) throws IllegalArgumentException
      Specified by:
      runTaskTimer in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimer

      @Deprecated public org.bukkit.scheduler.BukkitTask runTaskTimer(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay, long period) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTaskTimer in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimerAsynchronously

      public org.bukkit.scheduler.BukkitTask runTaskTimerAsynchronously(org.bukkit.plugin.Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException
      Specified by:
      runTaskTimerAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimerAsynchronously

      public void runTaskTimerAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<org.bukkit.scheduler.BukkitTask> task, long delay, long period) throws IllegalArgumentException
      Specified by:
      runTaskTimerAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • runTaskTimerAsynchronously

      @Deprecated public org.bukkit.scheduler.BukkitTask runTaskTimerAsynchronously(org.bukkit.plugin.Plugin plugin, org.bukkit.scheduler.BukkitRunnable task, long delay, long period) throws IllegalArgumentException
      Deprecated.
      Specified by:
      runTaskTimerAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
      Throws:
      IllegalArgumentException
    • getMainThreadExecutor

      @NotNull public @NotNull Executor getMainThreadExecutor(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      getMainThreadExecutor in interface org.bukkit.scheduler.BukkitScheduler
    • callSyncMethod

      public <T> Future<T> callSyncMethod(org.bukkit.plugin.Plugin plugin, Callable<T> task)
      Specified by:
      callSyncMethod in interface org.bukkit.scheduler.BukkitScheduler
    • syncIfNeeded

      public <T> T syncIfNeeded(Callable<T> task) throws Exception
      Runs a task on the primary thread, and blocks waiting for it to finish.
      Type Parameters:
      T - the task's return type
      Parameters:
      task - the task to run
      Returns:
      the task result
      Throws:
      Exception - if thrown by the task
    • cancelTask

      public void cancelTask(int taskId)
      Specified by:
      cancelTask in interface org.bukkit.scheduler.BukkitScheduler
    • cancelTasks

      public void cancelTasks(org.bukkit.plugin.Plugin plugin)
      Specified by:
      cancelTasks in interface org.bukkit.scheduler.BukkitScheduler
    • cancelAllTasks

      public void cancelAllTasks()
    • isCurrentlyRunning

      public boolean isCurrentlyRunning(int taskId)
      Specified by:
      isCurrentlyRunning in interface org.bukkit.scheduler.BukkitScheduler
    • isQueued

      public boolean isQueued(int taskId)
      Specified by:
      isQueued in interface org.bukkit.scheduler.BukkitScheduler
    • getActiveWorkers

      public List<org.bukkit.scheduler.BukkitWorker> getActiveWorkers()
      Returns active async tasks.
      Specified by:
      getActiveWorkers in interface org.bukkit.scheduler.BukkitScheduler
      Returns:
      active async tasks
    • getPendingTasks

      public List<org.bukkit.scheduler.BukkitTask> getPendingTasks()
      Returns tasks that still have at least one run remaining.
      Specified by:
      getPendingTasks in interface org.bukkit.scheduler.BukkitScheduler
      Returns:
      the tasks to be run