Players & Worlds
Players (players) and PlayerHandle
Section titled “Players (players) and PlayerHandle”Wraps the native PlayerRef surface (not exposed directly).
players.all()→PlayerHandle[]players.find(username)→PlayerHandle | nullplayers.require(username)→PlayerHandle(throws if missing)players.names()→ lowercase usernamesplayers.count()→ online player countplayers.message(username, text)→ send to one playerplayers.broadcast(text)→ send to everyoneplayers.disconnect(username, reason?)
All message arguments accept plain text or ui builders (UiText / UiMessage).
PlayerHandle surface
Section titled “PlayerHandle surface”getUsername()getId()→ UUID stringgetLanguage() / setLanguage(lang)isOnline()sendMessage(text)kick(reason?)getWorldName()
Example
Section titled “Example”players.broadcast("Welcome adventurers!");var player = players.find("Alice");if (player) { player.sendMessage("Hello " + player.getUsername());}Worlds (worlds) and WorldHandle
Section titled “Worlds (worlds) and WorldHandle”Wraps the native World class.
worlds.list()→ string[] of world namesworlds.get(name)→WorldHandle | nullworlds.getDefaultWorld()→WorldHandle | nullworlds.message(worldName, text)→ send to one worldworlds.hasWorld(name)→ booleanworlds.runOnWorldThread(worldName, callback)→ execute callback on world thread (required for ECS operations)
WorldHandle surface
Section titled “WorldHandle surface”getName()isLoaded()players()→PlayerHandle[]playerNames()→ string[]sendMessage(text)→ accepts string orUiText/UiMessage
Example
Section titled “Example”var world = worlds.getDefaultWorld();if (world) { world.sendMessage("A new dawn rises over " + world.getName());}
// Execute ECS operations safely from scheduler threadsserver.runRepeating(30000, function() { worlds.runOnWorldThread(null, function() { var onlinePlayers = players.all(); onlinePlayers.forEach(function(player) { var pos = ecs.getPosition(player.getId()); console.log(player.getUsername() + " at " + pos.x + ", " + pos.y + ", " + pos.z); }); });});Thread Safety
Section titled “Thread Safety”Important: ECS operations like ecs.getPosition(), ecs.teleport(), etc. must run on the world thread. Scheduler callbacks (server.runRepeating, server.runLater) execute on a separate thread, so wrap ECS calls in worlds.runOnWorldThread():
// Not supported: WRONG - will throw IllegalStateExceptionserver.runRepeating(5000, function() { var pos = ecs.getPosition(entityId); // Crashes!});
// ✅ CORRECT - wrapped in world threadserver.runRepeating(5000, function() { worlds.runOnWorldThread(null, function() { var pos = ecs.getPosition(entityId); // Safe });});