Back to home
SkriptMinecraftJava

Skript without blocking the main thread: MundoSK-Async

Hazar Akbuz · · 1 min read · Updated

Using async and sync sections with MundoSK-Async, which brings MundoSK's async feature to modern Skript versions.

Skript is a Bukkit plugin that lets server admins customise their servers without writing a plugin or paying someone to write one. Commands and events run on the server's main thread by default; if a slow job (file or network access, a heavy query) runs there, the whole server waits for it.

MundoSK-Async is a revisited version of MundoSK's async feature for modern Skript versions, published as open source in the projects.gg GitHub organisation.

As a section: async: and sync:

command /dispatchmeasync:
  trigger:
    set {_sender} to sender
    async:
      send "Hello %{_sender}%!"
      sync:
        send "Sync section!"

The async: section runs off the main thread; a nested sync: section returns to it. Define any local variable you need across sections (like {_sender} in the example) before the section starts.

As an effect: async and sync

command /dispatchmeasynceffect:
  trigger:
    send "This is not async!"
    async
    send "This is async!"
    sync
    send "Welcome back to sync!"

The effect form needs no indentation: the lines after async run asynchronously, and the sync line returns to the main thread.

When to switch back

Most of the Bukkit API cannot be called safely off the main thread. Leaving every step that touches the world, players or inventories to a sync section, and keeping the async part for work that waits, is the safest approach.

Building and credits

Build it with ./gradlew build in the project root; the output lands in ./build/libs. Thanks to Tlatoani, creator of MundoSK; nanodn, who forked MundoSK as MundoSK-Async; and TPGamesNL for Skript 2.6+ compatibility.