2020-05-02 16:14:47 +00:00
|
|
|
import { MiaoScriptConsole } from '@ccms/api'
|
2020-02-23 20:01:39 +00:00
|
|
|
|
2020-11-13 01:40:34 +00:00
|
|
|
let Nukkit = base.getInstance().getServer()
|
|
|
|
let LogLevel = Java.type('cn.nukkit.utils.LogLevel')
|
2020-02-23 20:01:39 +00:00
|
|
|
let CommandSender = Java.type('cn.nukkit.command.CommandSender')
|
|
|
|
|
|
|
|
export class NukkitConsole extends MiaoScriptConsole {
|
|
|
|
sender(sender, ...args) {
|
|
|
|
if (!(sender instanceof CommandSender)) {
|
|
|
|
this.error(`First parameter ${sender} not instanceof cn.nukkit.command.CommandSender can't send message!`)
|
2020-11-13 01:40:34 +00:00
|
|
|
return
|
2020-02-23 20:01:39 +00:00
|
|
|
}
|
|
|
|
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
|
|
|
|
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
|
|
|
} else {
|
2020-11-13 01:40:34 +00:00
|
|
|
sender.sendMessage(this.prefix + args.join(' '))
|
2020-02-23 20:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console(...args: string[]): void {
|
2020-11-13 01:40:34 +00:00
|
|
|
this.sender(Nukkit.getConsoleSender(), args.join(' '))
|
|
|
|
}
|
|
|
|
error(...args: any[]) {
|
|
|
|
this.logger.log(LogLevel.ERROR, this.name + args.join(' '))
|
2020-02-23 20:01:39 +00:00
|
|
|
}
|
|
|
|
}
|