fix: netty inject error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
d53287fc51
commit
8c6b75ff10
@ -62,8 +62,8 @@ export namespace event {
|
||||
return count;
|
||||
}
|
||||
|
||||
getJarFile(resource: string) {
|
||||
let dirs = Thread.currentThread().getContextClassLoader().getResources(resource);
|
||||
getJarFile(resource: string, loader?: any) {
|
||||
let dirs = (loader || Thread.currentThread().getContextClassLoader()).getResources(resource);
|
||||
if (dirs.hasMoreElements()) {
|
||||
let url = dirs.nextElement();
|
||||
if (url.protocol === "jar") { return url.openConnection().jarFile; }
|
||||
|
@ -19,7 +19,7 @@ export class BukkitEvent extends event.Event {
|
||||
}
|
||||
|
||||
getJarFile(resource: string) {
|
||||
return super.getJarFile('org/bukkit/Bukkit.class')
|
||||
return super.getJarFile('org/bukkit/Bukkit.class', Bukkit.class.classLoader)
|
||||
}
|
||||
isValidEvent(clazz: any): boolean {
|
||||
// 继承于 org.bukkit.event.Event
|
||||
|
@ -1,16 +1,9 @@
|
||||
import { server } from '@ms/api'
|
||||
import { server, constants } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
import chat from './enhance/chat'
|
||||
|
||||
const refList: Array<{ server: string, future: string }> = [
|
||||
{ server: 'aq', future: 'g' },//spigot 1.8.8
|
||||
{ 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;
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
@ -68,14 +61,24 @@ export class BukkitServer implements server.Server {
|
||||
|
||||
private reflectPipeline() {
|
||||
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
||||
let connection: any;
|
||||
let promise: any;
|
||||
for (const ref of refList) {
|
||||
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||
try {
|
||||
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||
} catch (error) {
|
||||
}
|
||||
connection = reflect.on(consoleServer).call(method).get()
|
||||
if (connection.class.name.indexOf('ServerConnection') !== -1) { break; }
|
||||
connection = undefined;
|
||||
} catch (error) { }
|
||||
}
|
||||
if (!promise) { console.error("Can't found ServerConnection or ChannelFuture !"); return }
|
||||
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
||||
for (const field of constants.Reflect.Field.listeningChannels) {
|
||||
try {
|
||||
promise = reflect.on(connection).get(field).get().get(0);
|
||||
if (promise.class.name.indexOf('Promise') !== -1) { break; }
|
||||
promise = undefined;
|
||||
} catch (error) { }
|
||||
}
|
||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
import { server } from '@ms/api'
|
||||
import { server, constants } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
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 TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
const File = Java.type("java.io.File");
|
||||
@ -64,14 +58,24 @@ export class SpongeServer implements server.Server {
|
||||
}
|
||||
private reflectPipeline() {
|
||||
let consoleServer = reflect.on(Sponge.getServer()).get()
|
||||
let connection: any;
|
||||
let promise: any;
|
||||
for (const ref of refList) {
|
||||
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||
try {
|
||||
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||
} catch (error) {
|
||||
}
|
||||
connection = reflect.on(consoleServer).call(method).get()
|
||||
if (connection.class.name.indexOf('ServerConnection') !== -1) { break; }
|
||||
connection = undefined;
|
||||
} catch (error) { }
|
||||
}
|
||||
if (!promise) { throw Error(`Can't found ServerConnection or ChannelFuture !`) }
|
||||
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
||||
for (const field of constants.Reflect.Field.listeningChannels) {
|
||||
try {
|
||||
promise = reflect.on(connection).get(field).get().get(0);
|
||||
if (promise.class.name.indexOf('Promise') !== -1) { break; }
|
||||
promise = undefined;
|
||||
} catch (error) { }
|
||||
}
|
||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user