ms/packages/nukkit/src/server.ts
MiaoWoo 3143851969 feat: use inversify autoProvide inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-26 10:15:33 +08:00

36 lines
1.1 KiB
TypeScript

import { server } from '@ms/api'
import { provideSingleton } from '@ms/container';
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
@provideSingleton(server.Server)
export class NukkitServer implements server.Server {
getPlayer(name: string) {
return Nukkit.getPlayer(name)
}
getVersion(): string {
return Nukkit.getVersion()
}
getOnlinePlayers() {
return Nukkit.getOnlinePlayers() as unknown as any[]
}
getConsoleSender() {
return Nukkit.getConsoleSender()
}
getService(service: string) {
return Nukkit.getServiceManager().getProvider(base.getClass(service))
}
dispatchCommand(sender: string | any, command: string): boolean {
if (typeof sender === 'string') {
sender = this.getPlayer(sender)
}
return Nukkit.dispatchCommand(sender, command)
}
dispatchConsoleCommand(command: string): boolean {
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command)
}
sendJson(sender: string | any, json: object | string): void {
throw new Error("Method not implemented.");
}
}