bukkit Running Tasks on the Main Thread


You can also make code run synchronously with the main thread using runTask. This is useful when you want to call Bukkit API methods after running code asynchronously from the main thread.

Code called inside of this Runnable will be executed on the main thread, making it safe to call Bukkit API methods.

Bukkit.getScheduler().runTask(plugin, new Runnable() {
    public void run() {
        Bukkit.broadcastMessage("This message is displayed to the server on the main thread");
        //Bukkit.broadcastMessage is thread-safe