Introduction to scripting
MCmdLogger supports scripting starting from version 3.5. You can use scripting api to create advanced attack scenarios and implement useful utilities in pure JavaScript.
Note that MCmdLogger scripting system isn't based on NodeJS. You can't use require(...) and other NodeJS-specific APIs.
Scripts are running in an isolated environment without direct access to operating system, files, network, etc.
caution
MCmdLogger's JS runtime doesn't fully implement ES6 standard (but fully supports ES5.1 and has partial support of ES6).
If you have at least some experience with JS build systems and bundlers, use one of these templates with preconfigured Babel and core-js polyfills for modern JS syntax support:
JavaScript - mcmdlogger-script-template
TypeScript - mcmdlogger-script-template-ts
Scripts usage
Scripts are being loaded from scripts directory, which must be in the same directory where MCmdLogger is running.
some-direcory/
┝╸ .mcmdlogger/ // MCmdLogger's cache files
┝╸ scripts/ // Scripts are loaded from this direcory
│ ┝╸ MyScript.js
│ ┕╸ AnotherScript.js
┕ mcmdlogger-neo // MCmdLogger executable
Scripts are written in JS, so MCmdLogger loads only files, which names end with .js.
Example script
playerJoin(player => {
player.on("player_message", event => {
if (event.text === "/ping") {
player.send("Pong!");
console.log("Pong sent to " + player.name);
}
})
})
command("kickall", () => {
players().forEach(player => player.kick())
console.log("All players kicked!")
})