ms/packages/nukkit/src/console.ts

22 lines
798 B
TypeScript
Raw Normal View History

2020-02-23 20:01:39 +00:00
import { MiaoScriptConsole } from '@ms/api'
let Nukkit = base.getInstance().getServer();
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!`)
return;
}
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
args[0].forEach(line => sender.sendMessage(this.prefix + line))
} else {
sender.sendMessage(this.prefix + args.join(' '));
}
}
console(...args: string[]): void {
this.sender(Nukkit.getConsoleSender(), args.join(' '));
}
}