Minestom wiki
Search…
Scripting

Project

Scripts are an alternative to Extensions, powerful and short but still with fewer features.
The scripting engine is open-source available here, built on top of GraalVM Polyglot API, there are multiple supported languages, for now, Javascript & Python.

Overview

Reddox is a command-based API, the only way to interact with the Minecraft server is to trigger commands and retrieve their data when needed. Signals are also available to execute code at specific moments.
1
// 'executor' is a global object, used to execute commands and listen to signals.
2
executor.run("tellraw Notch Hey");
3
4
// Commands can be registered using the command string syntax.
5
// Each command gets a callback with the sender and command metadata.
6
executor.registerCommand("entity Literal<get> Player<target>", (sender, context) => {
7
console.log("Retrieving " + context.target);
8
// let somePlayer = ...;
9
return somePlayer;
10
});
11
12
// Each command can return data, members are specified in documentation.
13
let player = executor.run("entity get Notch").entity;
14
console.log("You retrieved the player " + player.username + "!");
15
16
// Commands can be aliases for ease of use multiple times or shortening.
17
// {n} can be used to reference the nth argument during execution.
18
let getEntity = executor.make("entity get {0}", data => data.entity);
19
let entity = getEntity("Notch");
20
21
// 'signals' are general purpose listenable event,
22
// they can be game events, called with the '/signal' command,
23
// or from another script
24
executor.onSignal("move", (properties) => {
25
// Listen to player movement
26
// 'properties' contains data specific to the signal
27
let player = properties.player
28
let username = player.username
29
let position = properties.position
30
console.log("the player " + username + " moved to " + position)
31
});
32
33
// Signals can also be used to send data
34
executor.onSignal("my_signal", (properties, output) => {
35
output.value = "I am a text"
36
});
37
38
// ... and be retrieved back
39
let output = executor.signal("my_signal")
40
console.log("Value: " + output.value) // -> "I am a text"
Copied!

Setup

All scripts should be available in the scripts/ folder. They can either be contained within a single file or in a folder, the structure is as follow:
1
scripts/
2
- randomscript.js // Individual file can have the name you want
3
- myscript.js
4
- Essentials/ // The folder name will be used in the '/script' command
5
- main.js // -> "main.js" is the main file used to initialize the script
6
- Config.js
7
- WorldGuard/
8
- main.js
9
- Config.js
10
- Regions.js
Copied!
In Java, loading scripts is as simple as calling a single method:
1
ScriptManager.load();
Copied!
ScriptManager contains everything you would need to interacts with scripts, learn more about it here.
Last modified 3mo ago
Copy link