OpenJS-docs
Download plugin
  • Overview
    • Welcome
  • Getting Started
    • Installing the plugin
    • Configuration file
    • Commands
    • Creating scripts
  • OpenJS Components
    • Feature Flags
    • Managing scripts within scripts
    • Sharing variables between scripts
    • Custom Commands
    • Using PlaceHolderApi
    • Listening and cancelling events
    • Custom events
    • Loading and saving data
    • Logging in console
    • Scheduling
    • Java imports
  • Example Scripts
    • spawn hit stand command
    • Knockbackstick command
    • No hit-cooldown script
    • NoBlockPlacing script
    • Saving Player data script
    • running code asynchronously
    • WhileTrue do script
Powered by GitBook
On this page
  1. Example Scripts

running code asynchronously

asyncscript.js
var Bukkit = org.bukkit.Bukkit;

Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("OpenJS"), new java.lang.Runnable({
    run: 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
    }
}));
PreviousSaving Player data scriptNextWhileTrue do script

Last updated 7 days ago