2020-05-02 16:14:47 +00:00
|
|
|
import { server, task } from '@ccms/api'
|
|
|
|
import { provideSingleton, inject, postConstruct } from '@ccms/container'
|
2020-04-01 03:08:15 +00:00
|
|
|
|
2020-05-02 16:14:47 +00:00
|
|
|
import * as reflect from '@ccms/common/dist/reflect'
|
2020-01-15 08:43:00 +00:00
|
|
|
|
2020-09-22 07:29:12 +00:00
|
|
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
2020-01-15 08:43:00 +00:00
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(server.Server)
|
2020-01-15 08:43:00 +00:00
|
|
|
export class BungeeServer implements server.Server {
|
2020-09-22 07:29:12 +00:00
|
|
|
private pluginsFolder: string
|
|
|
|
private pipeline: any
|
|
|
|
private rootLogger: any
|
2020-04-01 03:08:15 +00:00
|
|
|
|
|
|
|
@inject(task.TaskManager)
|
|
|
|
private task: task.TaskManager
|
2020-03-01 07:19:43 +00:00
|
|
|
|
|
|
|
constructor() {
|
2020-09-22 07:29:12 +00:00
|
|
|
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath()
|
2020-03-01 07:19:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 03:08:15 +00:00
|
|
|
@postConstruct()
|
|
|
|
initialize() {
|
2020-09-22 07:29:12 +00:00
|
|
|
let count = 0
|
2020-04-01 03:08:15 +00:00
|
|
|
let wait = this.task.create(() => {
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
|
2020-09-22 07:29:12 +00:00
|
|
|
wait.cancel()
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (ex: any) {
|
2020-04-01 03:08:15 +00:00
|
|
|
count++
|
|
|
|
if (count > 50) {
|
|
|
|
console.error('Reflect BungeeCord netty channel pipeline error time > 50times. Err: ' + ex)
|
|
|
|
wait.cancel()
|
|
|
|
} else {
|
|
|
|
console.warn('Wait BungeeCord start ready to get netty channel pipeline. Err: ' + ex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).later(10).timer(20).submit()
|
2020-05-15 07:48:38 +00:00
|
|
|
try {
|
|
|
|
this.rootLogger = Bungee.getLogger()
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-05-15 07:48:38 +00:00
|
|
|
console.error("Can't found rootLogger!")
|
|
|
|
}
|
2020-04-01 03:08:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 08:43:00 +00:00
|
|
|
getPlayer(name: string) {
|
2020-09-22 07:29:12 +00:00
|
|
|
return Bungee.getPlayer(name)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
getVersion(): string {
|
|
|
|
return Bungee.getVersion()
|
|
|
|
}
|
|
|
|
getOnlinePlayers() {
|
|
|
|
return Bungee.getPlayers()
|
|
|
|
}
|
|
|
|
getConsoleSender() {
|
|
|
|
return Bungee.getConsole()
|
|
|
|
}
|
|
|
|
getService(service: string) {
|
2020-09-22 07:29:12 +00:00
|
|
|
throw new Error("Method not implemented.")
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
2021-10-25 07:54:38 +00:00
|
|
|
broadcast(message: string, permission: string) {
|
|
|
|
return Bungee.broadcast(message)
|
|
|
|
}
|
|
|
|
broadcastMessage(message: string) {
|
|
|
|
return Bungee.broadcast(message)
|
|
|
|
}
|
2020-01-15 08:43:00 +00:00
|
|
|
dispatchCommand(sender: string | any, command: string): boolean {
|
2020-01-16 09:19:10 +00:00
|
|
|
if (typeof sender === 'string') {
|
|
|
|
sender = this.getPlayer(sender)
|
|
|
|
}
|
|
|
|
return Bungee.getPluginManager().dispatchCommand(sender, command)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
dispatchConsoleCommand(command: string): boolean {
|
2020-01-16 09:19:10 +00:00
|
|
|
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
2020-02-29 14:28:43 +00:00
|
|
|
getPluginsFolder(): string {
|
2020-09-22 07:29:12 +00:00
|
|
|
return this.pluginsFolder
|
2020-03-01 07:19:43 +00:00
|
|
|
}
|
|
|
|
getNativePluginManager() {
|
2020-03-01 11:37:34 +00:00
|
|
|
return Bungee.getPluginManager() as any
|
2020-02-29 14:28:43 +00:00
|
|
|
}
|
2020-04-01 03:08:15 +00:00
|
|
|
getNettyPipeline() {
|
2020-09-22 07:29:12 +00:00
|
|
|
return this.pipeline
|
2020-04-01 03:08:15 +00:00
|
|
|
}
|
2020-05-15 07:48:38 +00:00
|
|
|
getRootLogger() {
|
2020-09-22 07:29:12 +00:00
|
|
|
return this.rootLogger
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
}
|