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. OpenJS Components

Scheduling

function broadcastEntityCount() {
    var server = plugin.getServer();
    var entityCount = 0;
    var worlds = server.getWorlds();

    for (var i = 0; i < worlds.size(); i++) {
        var world = worlds.get(i);
        entityCount += world.getEntities().size();
    }

    server.broadcastMessage("Total entities: " + entityCount);
}

// Register the schedule to run every 10 seconds (200 ticks)
registerSchedule(0, 200, this, "broadcastEntityCount");

Or:

// Register the schedule to run every 10 seconds (200 ticks)
registerSchedule(0, 200, {
        handler: function() {
            var server = plugin.getServer();
            var entityCount = 0;
            var worlds = server.getWorlds();
            
            for (var i = 0; i < worlds.size(); i++) {
                var world = worlds.get(i);
                entityCount += world.getEntities().size();
            }
            
            server.broadcastMessage("Total entities: " + entityCount);
    }}, "handler");

This is not a complete documentation on scheduling

PreviousLogging in consoleNextJava imports

Last updated 6 days ago