LogoLogo
JavaDocsVersions
  • Introduction
  • Getting started
    • Dependencies
    • Your first server
  • Feature
    • Adventure
    • Player capabilities
    • Events
      • Implementation
      • Server list ping
    • Items
    • Entities
      • AI
    • Tags
    • Schedulers
    • Commands
    • Inventories
    • Player UUID
    • Player skin
    • Permissions
    • Advancements
    • Map rendering
      • GLFWMapRendering
    • Query system
    • Open to LAN
  • Thread Architecture
    • Thread safety in the JVM
    • Acquirable API
      • The inside
  • World
    • Instances
    • Chunk management
      • Anvil Loader
    • Blocks
    • Coordinates
    • Generation
    • Batch
  • Extension System
    • Extensions
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Feature

Schedulers

A Scheduler is an object able to schedule tasks based on a condition (time, tick rate, future, etc...) with a precision linked to its ticking rate. It is therefore important to remember that Minestom scheduling API does not aim to replace JDK's executor services which should still be used if you do not need our scheduling guarantee (execution in the caller thread, execution based on tick, less overhead).

Those tasks scheduling can be configured using a TaskSchedule object, defining when the task is supposed to execute.

Scheduler scheduler = MinecraftServer.getSchedulerManager();
scheduler.scheduleNextTick(() -> System.out.println("Hey!"));
scheduler.submitTask(() -> {
    System.out.println("Running directly and then every second!");
    return TaskSchedule.seconds(1);
});

Tasks are by default executed synchronously (in the object ticking thread). Async execution is possible, but you may consider using a third party solution.

Scheduling will give you a Task object, giving you an overview of the task state, and allow some modification such as cancelling.

Scheduler scheduler = player.scheduler();
Task task = scheduler.scheduleNextTick(() -> System.out.println("Hey!"));
task.cancel();
PreviousTagsNextCommands

Last updated 1 year ago

Was this helpful?