task

Allows for seamless scheduling with multithreading and the server

Overview:

Functions:

API Reference

spawn()

Runs a function asynchronously.

  • Bukkit: Uses async scheduler

  • Folia: Runs on a separate thread

Parameters:

  • function (Function) Function to execute.

Returns:

  • taskId (Number) Identifier used to cancel the task.


main()

Executes a function safely on the server main thread. (If on Folia use task.entitySchedule(..) instead)

Parameters:

  • function (Function) Function to execute.

Returns:

  • taskId (Number)


entitySchedule()

Schedules a task bound to a specific entity. (Folia alternative to task.main(..))

Parameters:

  • entity (Entity) The entity to bind the task to.

  • function (Function) Function to execute.

Returns:

  • taskId (Number)


thread()

Executes a function parallel on a thread.

Parameters:

  • function (Function) Function to execute.

Returns:

  • taskId (Number)


delay()

Executes a function after a delay asynchronously.

Parameters:

  • delay (Number) Delay in seconds.

  • function (Function) Function to execute.

Returns:

  • taskId (Number)


repeat()

Runs a repeating task asynchronously .

Parameters:

  • delay (Number) Initial delay in seconds.

  • period (Number) Repeat interval in ticks.

  • function (Function) Function to run.

Returns:

  • taskId (Number)


cancel()

Cancels a scheduled task.

Parameters:

  • taskId (Number) The task identifier.


bindToUnload()

Registers a function to be executed when the script unloads.

Parameters:

  • function (Function) Cleanup handler.


wait()

Pauses execution of the current script for a given number of seconds.

Parameters:

  • seconds (Number) Time to wait in seconds.

Returns:

  • Boolean Returns true when completed. Throws if interrupted.


waitForScript()

Blocks execution until specified script finishes loading.

Parameters:

  • scriptName (String) Name of the script to wait for.


waitForPlugin()

Blocks execution until a plugin becomes available.

Parameters:

  • pluginName (String) Name of the plugin.

Last updated

Was this helpful?