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
| Argument | Description |
|---|---|
| name | Command keyword, must contain only lowercase English letters, numbers and "_" |
| usage | Command arguments hint (example: "<required arg> [optional arg] (switch 1|switch 2)") |
| description | Command description, displayed in help |
| callback | Callback 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")
})