Interface PluginTask.Builder

Enclosing interface:
PluginTask<V>

public static interface PluginTask.Builder
A helper object for building and scheduling a PluginTask.
 
      final PluginScheduler scheduler = DistributorProvider.get().getPluginScheduler();
      final MindustryPlugin plugin = ...;
      // Warn the players the server is close in 5 minutes.
      Groups.player.each(p -> p.sendMessage("The server will restart in 5 minutes."));
      // Now schedule the closing task.
      scheduler.scheduleSync(plugin).delay(5L, MindustryTimeUnit.MINUTES).execute(() -> Core.app.exit());
  
  • Method Details

    • async

      PluginTask.Builder async(boolean async)
    • delay

      PluginTask.Builder delay(long delay, MindustryTimeUnit unit)
      Run the task after a delay.
      Parameters:
      delay - the delay.
      unit - the time unit of the delay.
      Returns:
      this builder.
    • repeat

      PluginTask.Builder repeat(long interval, MindustryTimeUnit unit)
      Run the task periodically with a fixed interval. Stops the periodic execution if an exception is thrown.
      Parameters:
      interval - the interval between the end of the last execution and the start of the next.
      unit - the time unit of the interval.
      Returns:
      this builder.
    • execute

      PluginTask<Void> execute(Runnable runnable)
      Build and schedule the task with the given task.
      Parameters:
      runnable - the task to run.
      Returns:
      a new plugin task.
    • execute

      PluginTask<Void> execute(Consumer<Cancellable> consumer)
      Build and schedule the task with the given task.
      Parameters:
      consumer - the task to run, with a cancellable object to stop the task if it's periodic.
      Returns:
      a new plugin task.
    • execute

      <V> PluginTask<V> execute(Supplier<V> supplier)
      Build and schedule the task with the given task.
      Parameters:
      supplier - the task to run, with an output value. Won't output any result value if the task is periodic.
      Returns:
      a new plugin task.