Skip to content

JavaScript Scripting

CoreLib provides a GraalJS-based JavaScript scripting system. Scripts can be invoked from action lists through runjs, runscript, or javascript.

This page summarizes the CoreLib JavaScript scripting system for the English documentation.

Basic Usage

Place scripts under:

text
plugins/EmakiCoreLib/scripts/

Common directories include:

text
scripts/
├── global/
├── forge/
├── strengthen/
├── cooking/
├── gem/
├── skills/
├── item/
├── attribute/
├── templates/
└── examples/

Example action:

yaml
actions:
  - 'runjs script=examples/hello.js'

Example script:

js
function main(ctx) {
  emaki.logger.info("Hello from Emaki JavaScript.");

  if (emaki.player.exists()) {
    emaki.player.sendMessage("[EmakiJS] Hello, " + emaki.player.name() + "!");
  }

  return true;
}

Exposed APIs

Scripts can use the injected emaki object:

APIPurpose
emaki.contextRead action context, placeholders, attributes, and arguments.
emaki.playerRead player information and send messages.
emaki.itemRead contextual ItemStack information.
emaki.actionDispatch CoreLib actions from scripts.
emaki.loggerWrite script-prefixed logs.
emaki.randomGenerate random values.
emaki.stateStore temporary shared state in the current action context.
emaki.textText utility methods.

Security Notes

The default configuration disables host class lookup, IO, threads, native access, and environment access. Production servers should keep these safe defaults unless they fully understand the risks.