running code on the main thread

Bukkit / Non Folia:

asyncscript.js
task.spawn(function() {
   // code you want to execute in the main thread here
   // example: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
   // dispatchCommand only works in the main thread, allowing the script to execute commands
})

Folia:

asyncscript.js
task.entitySchedule(player, function() {
  player.sendMessage("This was run in your entity thread!");
  // code you want to execute in the thread here
  // example: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
  // dispatchCommand only works in the thread the entity is in, allowing the script to execute commands
});

Last updated