2022-04-01 09:18:32 +00:00
|
|
|
import { server } from '@ccms/api'
|
2020-07-28 01:39:52 +00:00
|
|
|
import { provideSingleton } from '@ccms/container'
|
2020-01-14 09:44:20 +00:00
|
|
|
|
2020-05-02 16:14:47 +00:00
|
|
|
import * as reflect from '@ccms/common/dist/reflect'
|
2020-01-14 09:44:20 +00:00
|
|
|
|
2022-04-01 09:18:32 +00:00
|
|
|
const Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit')
|
2020-01-14 09:44:20 +00:00
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(server.Server)
|
2020-06-02 09:50:47 +00:00
|
|
|
export class BukkitServer extends server.ReflectServer {
|
2020-07-28 01:39:52 +00:00
|
|
|
private pluginsFolder: string
|
2020-03-01 07:19:43 +00:00
|
|
|
|
|
|
|
constructor() {
|
2020-07-28 01:39:52 +00:00
|
|
|
super()
|
|
|
|
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath()
|
2020-03-01 07:19:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 09:44:20 +00:00
|
|
|
getPlayer(name: string) {
|
2020-10-02 08:43:18 +00:00
|
|
|
return Bukkit.getPlayerExact(name)
|
2020-01-14 09:44:20 +00:00
|
|
|
}
|
|
|
|
getVersion(): string {
|
|
|
|
return Bukkit.getVersion()
|
|
|
|
}
|
|
|
|
getOnlinePlayers() {
|
2020-10-02 08:43:18 +00:00
|
|
|
return Bukkit.getOnlinePlayers()
|
2020-01-14 09:44:20 +00:00
|
|
|
}
|
|
|
|
getConsoleSender() {
|
|
|
|
return Bukkit.getConsoleSender()
|
|
|
|
}
|
|
|
|
getService(service: string) {
|
|
|
|
return Bukkit.getServicesManager().getRegistration(base.getClass(service))?.getProvider()
|
|
|
|
}
|
2021-10-25 07:54:38 +00:00
|
|
|
broadcast(message: string, permission: string) {
|
|
|
|
return Bukkit.broadcast(message, permission)
|
|
|
|
}
|
|
|
|
broadcastMessage(message: string) {
|
|
|
|
return Bukkit.broadcastMessage(message)
|
|
|
|
}
|
2020-01-14 09:44:20 +00:00
|
|
|
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 {
|
2020-07-28 01:39:52 +00:00
|
|
|
return this.pluginsFolder
|
2020-03-01 07:19:43 +00:00
|
|
|
}
|
|
|
|
getNativePluginManager() {
|
2020-07-28 01:39:52 +00:00
|
|
|
return Bukkit.getPluginManager() as any
|
2020-02-29 14:28:43 +00:00
|
|
|
}
|
2020-06-02 09:50:47 +00:00
|
|
|
getDedicatedServer() {
|
|
|
|
return reflect.on(Bukkit.getServer()).get('console').get()
|
|
|
|
}
|
2020-04-01 03:08:15 +00:00
|
|
|
getNettyPipeline() {
|
2020-07-28 01:39:52 +00:00
|
|
|
return this.pipeline
|
2020-04-01 03:08:15 +00:00
|
|
|
}
|
2020-05-15 07:48:38 +00:00
|
|
|
getRootLogger() {
|
2020-07-28 01:39:52 +00:00
|
|
|
return this.rootLogger
|
2020-05-15 07:48:38 +00:00
|
|
|
}
|
2020-01-14 09:44:20 +00:00
|
|
|
}
|