Skip to content

Environment Capabilities and Channels ​

Environment capability injection: $send wrapper (the underlying bridge $_send is an internal implementation, held in the init.js closure and not exposed globally), channel descriptions, runtime configuration (plugins/Yeow/runtime/config.yml).

Environment Capability Injection ​

PluginThread registers a single underlying function in the JS context; init.js holds it in a closure and immediately removes it from the global object — plugin code can only use the wrapped $send:

FunctionSignatureDescription
$_send(channel, t, p)(string, string | null, string | null) => string | number | nullThe sole JS→Java communication entry (internal implementation, not exposed globally)

Supported message channels:

ChannelPurposeHandling Location
taskGame tasks (requests/get blocks/teleport, etc.)Main thread scheduler
timerTimers (setTimeout/setInterval)Plugin thread Timer thread pool
fsFile system read/writePlugin thread handles directly
httpHTTP server/clientPlugin thread handles directly
assetsPlugin built-in resource readingPlugin thread handles directly
serviceService registration/request/subscribe/publishServiceManager
debugError reporting / heartbeat ping-pongPlugin thread handles directly
logConsole logging (auto-adds [PluginName] prefix)Plugin thread handles directly
envRuntime environment info (static snapshot; no timestamp)Plugin thread handles directly
lifecycleLifecycle confirmation (unloadDone)Plugin thread handles directly

$send Wrapper Layer ​

init.js wraps $_send into $send(channel, t, p): channel is the namespace, t the operation/type (nullable) and p the params object (nullable); JSON conversion is automatic. $_send only exists within the init.js closure — plugin code (including dependency packages) that calls $_send directly will receive a ReferenceError:

js
// $send(channel, t, p) (the only usable entry point for plugins)
$send('task', 'player.get', { params: { identifier: 'uuid' } });

Channel Descriptions ​

task channel — Game tasks, routed through the main thread scheduler. Frame: t = task type, p = { params, cb?, priority? }:

js
$send('task', 'player.get', { params: { identifier: 'uuid' } });              // sync
$send('task', 'player.get', { params: { identifier: 'uuid' }, cb: 'cb_1' });  // async
$send('task', null, { tasks: [{ type: 'server.getVersion' }] });              // batch (t empty)

Synchronous tasks (no cb) block and wait for the result; asynchronous tasks (with cb) resolve via callback Promise.

timer channel — Replaces $timeout/$interval. Frame: t = timeout / interval / clear, p = { cb, delay? }:

js
$send('timer', 'timeout', { cb: 'cb_1', delay: 1000 });
$send('timer', 'interval', { cb: 'cb_2', delay: 5000 });
$send('timer', 'clear', { cb: 'cb_1' });

log channel — Console logging auto-adds the [PluginName] prefix:

js
console.log('hello');     // → [MyPlugin] hello
console.warn('warning');  // → [MyPlugin] warning

reportError channel — Manually report errors to dev-server source-map resolution:

js
import { logError } from 'yeow-api';
try { riskyOp(); } catch (e) { logError(e, 'custom context'); }

lifecycle channel — Lifecycle confirmation (used internally by plugins):

js
$send('lifecycle', 'unloadDone');   // Confirmation of disable or hot-reload completion

The JS side sends $send('lifecycle', 'unloadDone') to the Java side for confirmation after the onUnload callback has finished executing. Upon receiving the confirmation, the Java side sets running = false, and the message loop exits naturally.

Wrapper Layer ​

init.js wraps $_send into a standard JS API:

$_send(channel, t, p)   ← The only Java-native function (held in init.js closure, not exposed globally)
    ↓
init.js wrapper layer
    ├── $send(channel, t, p)   ← Automatic JSON conversion (the only usable entry point for plugins)
    ├── console.log/warn/error   ← Auto-adds [pluginName] prefix
    ├── setTimeout / clearTimeout
    ├── setInterval / clearInterval
    ├── fetch                    ← HTTP fetch (Promise)
    └── $hm                      ← Message dispatcher

Runtime Configuration ​

For the complete reference of plugins/Yeow/runtime/config.yml (auto-generated on first startup), including the Folia section and warning configuration, see Operations - Runtime Configuration; for warning thresholds and dynamic scaling, see Runtime Warning Guide.