Skip to main content

Command hook

Command hook is used to register new console command in MCmdLogger. It has several implementations:

command(name: string, callback: (command: string) => any)
command(name: string, description: string, callback: (command: string) => any)
command(name: string, usage: string, description: string, callback: (command: string) => any)

Reference

ArgumentDescription
nameCommand keyword, must contain only lowercase English letters, numbers and "_"
usageCommand arguments hint (example: "<required arg> [optional arg] (switch 1|switch 2)")
descriptionCommand description, displayed in help
callbackCallback function, takes command args string as arg (args are space-separated)

Example

command("kick_by_uuid", "<uuid>", "Kicks player by UUID", command => {
const args = command.split(" ")
if (command === "" || args.length !== 1) {
console.log("Invalid args")
return
}
for (const p of players()) {
if (p.uuid === args[0]) {
p.kick()
console.log("Player " + p.name + " kicked")
return
}
}
console.log("Player not found")
})