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

WhileTrue do script

whileloop.js
function broadcastMessage() {
    plugin.getServer().broadcastMessage("Hello, this is a broadcast message!");
}

// Function to start the broadcast loop
function startBroadcastLoop() {
    while (true) {
        broadcastMessage();
        // Sleep for 10 seconds (20 ticks = 1 second in Minecraft)
        java.lang.Thread.sleep(2000); // 10 seconds = 10,000 milliseconds = 20 ticks * 1000 milliseconds
    }
}

// Start the broadcast loop
startBroadcastLoop();
Previousrunning code asynchronously

Last updated 7 days ago