ms/packages/nukkit/src/server.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-02-23 20:01:39 +00:00
import { server } from '@ms/api'
import { provideSingleton } from '@ms/container';
2020-02-23 20:01:39 +00:00
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
@provideSingleton(server.Server)
2020-02-23 20:01:39 +00:00
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.");
}
}