2020-01-14 09:44:20 +00:00
|
|
|
import { server } from '@ms/api'
|
2020-02-26 02:15:33 +00:00
|
|
|
import { provideSingleton } from '@ms/container';
|
2020-01-14 09:44:20 +00:00
|
|
|
|
|
|
|
import chat from './enhance/chat'
|
|
|
|
|
|
|
|
let Bukkit = org.bukkit.Bukkit;
|
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(server.Server)
|
2020-01-14 09:44:20 +00:00
|
|
|
export class BukkitServer implements server.Server {
|
|
|
|
getPlayer(name: string) {
|
|
|
|
return Bukkit.getPlayer(name)
|
|
|
|
}
|
|
|
|
getVersion(): string {
|
|
|
|
return Bukkit.getVersion()
|
|
|
|
}
|
|
|
|
getOnlinePlayers() {
|
|
|
|
return Bukkit.getOnlinePlayers() as unknown as any[]
|
|
|
|
}
|
|
|
|
getConsoleSender() {
|
|
|
|
return Bukkit.getConsoleSender()
|
|
|
|
}
|
|
|
|
getService(service: string) {
|
|
|
|
return Bukkit.getServicesManager().getRegistration(base.getClass(service))?.getProvider()
|
|
|
|
}
|
|
|
|
dispatchCommand(sender: string | any, command: string): boolean {
|
|
|
|
if (typeof sender === 'string') {
|
|
|
|
sender = this.getPlayer(sender)
|
|
|
|
}
|
|
|
|
return Bukkit.dispatchCommand(sender, command)
|
|
|
|
}
|
|
|
|
dispatchConsoleCommand(command: string): boolean {
|
|
|
|
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)
|
|
|
|
}
|
2020-02-29 14:28:43 +00:00
|
|
|
getPluginsFolder(): string {
|
|
|
|
return Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
|
|
|
}
|
2020-01-14 09:44:20 +00:00
|
|
|
sendJson(sender: string | any, json: object | string): void {
|
|
|
|
if (typeof sender === "string") {
|
|
|
|
sender = this.getPlayer(sender)
|
|
|
|
}
|
|
|
|
let result = chat.json(sender, json)
|
|
|
|
if (result !== false) {
|
|
|
|
this.dispatchConsoleCommand(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|