Class PluginSchedulerBuilder

java.lang.Object
one.tranic.irs.PluginSchedulerBuilder

public class PluginSchedulerBuilder extends Object
Builder class for scheduling tasks in a Bukkit or Folia environment. Supports synchronous and asynchronous execution with various scheduling options.

Usage example:

 
 PluginSchedulerBuilder.builder(plugin)
     .sync()
     .task(() -> Bukkit.getLogger().info("Task executed!"))
     .delayTicks(20L)
     .run();
 
 
  • Constructor Details

    • PluginSchedulerBuilder

      public PluginSchedulerBuilder(org.bukkit.plugin.Plugin plugin)
      Constructs a new PluginSchedulerBuilder for the given plugin. Automatically detects the platform to adjust behavior for Folia or Spigot.
      Parameters:
      plugin - the plugin instance to associate with this scheduler builder
  • Method Details

    • builder

      public static PluginSchedulerBuilder builder(org.bukkit.plugin.Plugin plugin)
      Creates a new instance of PluginSchedulerBuilder.
      Parameters:
      plugin - the plugin instance to associate with this scheduler builder
      Returns:
      a new PluginSchedulerBuilder instance
    • cancelTasks

      public void cancelTasks()
    • sync

      public PluginSchedulerBuilder sync()
      Configures the task to run synchronously.
      Returns:
      this builder instance for method chaining
    • sync

      public PluginSchedulerBuilder sync(@NotNull @NotNull org.bukkit.Location location)
      Configures the task to run synchronously at the specified location.
      Parameters:
      location - the location where the task will execute synchronously
      Returns:
      this builder instance for method chaining
    • sync

      public PluginSchedulerBuilder sync(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Configures the task to run synchronously on the specified entity.
      Parameters:
      entity - the entity where the task will execute synchronously
      Returns:
      this builder instance for method chaining
    • async

      public PluginSchedulerBuilder async()
      Configures the task to run asynchronously.
      Returns:
      this builder instance for method chaining
    • task

      public PluginSchedulerBuilder task(@NotNull @NotNull Runnable runnable)
      Sets the task to be executed.
      Parameters:
      runnable - the task to execute
      Returns:
      this builder instance for method chaining
    • task

      public PluginSchedulerBuilder task(@NotNull Consumer<? super TaskImpl<org.bukkit.plugin.Plugin>> task)
      Sets the task to be executed.
      Parameters:
      task - the task to execute
      Returns:
      this builder instance for method chaining
    • delayTicks

      public PluginSchedulerBuilder delayTicks(long delayTicks)
      Sets the initial delay in ticks before the task is executed.
      Parameters:
      delayTicks - the number of ticks to delay
      Returns:
      this builder instance for method chaining
    • period

      public PluginSchedulerBuilder period(long period)
      Sets the period in ticks between consecutive executions of the task.
      Parameters:
      period - the number of ticks between executions
      Returns:
      this builder instance for method chaining
    • run

      @Nullable public @Nullable TaskImpl<org.bukkit.plugin.Plugin> run()
      Builds and schedules the task based on the configured parameters.
      Returns:
      a TaskImpl representing the scheduled task. Null if using Consumer on non-Folia.
      Throws:
      UnsupportedOperationException - if the task is not set