feat: add pipeline reflect
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
d22cb515f7
commit
f9458e66c1
@ -30,6 +30,7 @@ export namespace server {
|
|||||||
dispatchConsoleCommand(command: string): boolean;
|
dispatchConsoleCommand(command: string): boolean;
|
||||||
getPluginsFolder(): string;
|
getPluginsFolder(): string;
|
||||||
getNativePluginManager(): NativePluginManager;
|
getNativePluginManager(): NativePluginManager;
|
||||||
|
getNettyPipeline(): any;
|
||||||
sendJson(sender: string | any, json: object | string): void;
|
sendJson(sender: string | any, json: object | string): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
import chat from './enhance/chat'
|
import chat from './enhance/chat'
|
||||||
|
|
||||||
|
const refList: Array<{ server: string, future: string }> = [
|
||||||
|
{ server: 'an', future: 'g' },//spigot 1.12.2
|
||||||
|
{ server: 'getServerConnection', future: 'f' },//after spigot 1.14.4
|
||||||
|
{ server: 'func_147137_ag', future: 'field_151274_e' }//catserver 1.12.2
|
||||||
|
]
|
||||||
|
|
||||||
let Bukkit = org.bukkit.Bukkit;
|
let Bukkit = org.bukkit.Bukkit;
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class BukkitServer implements server.Server {
|
export class BukkitServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
||||||
|
this.reflectPipeline()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@ -43,6 +52,9 @@ export class BukkitServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Bukkit.getPluginManager() as any;
|
return Bukkit.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
sender = this.getPlayer(sender)
|
||||||
@ -52,4 +64,17 @@ export class BukkitServer implements server.Server {
|
|||||||
this.dispatchConsoleCommand(result)
|
this.dispatchConsoleCommand(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private reflectPipeline() {
|
||||||
|
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
||||||
|
let promise: any;
|
||||||
|
for (const ref of refList) {
|
||||||
|
try {
|
||||||
|
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!promise) { throw Error(`Can't found ServerConnection or ChannelFuture !`) }
|
||||||
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,42 @@
|
|||||||
import { server } from '@ms/api'
|
import { server, task } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton, inject, postConstruct } from '@ms/container'
|
||||||
|
|
||||||
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class BungeeServer implements server.Server {
|
export class BungeeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
|
@inject(task.TaskManager)
|
||||||
|
private task: task.TaskManager
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
initialize() {
|
||||||
|
let count = 0;
|
||||||
|
let wait = this.task.create(() => {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
|
||||||
|
wait.cancel();
|
||||||
|
} catch (ex) {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bungee.getPlayer(name);
|
return Bungee.getPlayer(name);
|
||||||
}
|
}
|
||||||
@ -41,6 +67,9 @@ export class BungeeServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Bungee.getPluginManager() as any
|
return Bungee.getPluginManager() as any
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ export class BungeeTask extends task.Task {
|
|||||||
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
||||||
}
|
}
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, this.interval, TimeUnit.MILLISECONDS)
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
||||||
} else {
|
} else {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, TimeUnit.MILLISECONDS)
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,4 +198,4 @@ export = {
|
|||||||
accessible,
|
accessible,
|
||||||
declaredMethods,
|
declaredMethods,
|
||||||
mapToObject
|
mapToObject
|
||||||
};
|
}
|
||||||
|
@ -42,6 +42,9 @@ export class NukkitServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Nukkit.getPluginManager() as any;
|
return Nukkit.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
import * as fs from '@ms/common/dist/fs'
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
|
const refList: Array<{ server: string, future: string }> = [
|
||||||
|
{ server: 'an', future: 'g' },//spigot 1.12.2
|
||||||
|
{ server: 'getServerConnection', future: 'f' },//after spigot 1.14.4
|
||||||
|
{ server: 'func_147137_ag', future: 'field_151274_e' }//catserver 1.12.2
|
||||||
|
]
|
||||||
|
|
||||||
const Sponge = org.spongepowered.api.Sponge;
|
const Sponge = org.spongepowered.api.Sponge;
|
||||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||||
const URL = Java.type("java.net.URL");
|
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class SpongeServer implements server.Server {
|
export class SpongeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||||
|
this.reflectPipeline()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@ -46,10 +53,25 @@ export class SpongeServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Sponge.getPluginManager() as any;
|
return Sponge.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
sender = this.getPlayer(sender)
|
||||||
}
|
}
|
||||||
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
||||||
}
|
}
|
||||||
|
private reflectPipeline() {
|
||||||
|
let consoleServer = reflect.on(Sponge.getServer()).get()
|
||||||
|
let promise: any;
|
||||||
|
for (const ref of refList) {
|
||||||
|
try {
|
||||||
|
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!promise) { throw Error(`Can't found ServerConnection or ChannelFuture !`) }
|
||||||
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user