fix: netty inject error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
acbeda9659
commit
8e5588ca23
@ -62,8 +62,8 @@ export namespace event {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
getJarFile(resource: string) {
|
getJarFile(resource: string, loader?: any) {
|
||||||
let dirs = Thread.currentThread().getContextClassLoader().getResources(resource);
|
let dirs = (loader || Thread.currentThread().getContextClassLoader()).getResources(resource);
|
||||||
if (dirs.hasMoreElements()) {
|
if (dirs.hasMoreElements()) {
|
||||||
let url = dirs.nextElement();
|
let url = dirs.nextElement();
|
||||||
if (url.protocol === "jar") { return url.openConnection().jarFile; }
|
if (url.protocol === "jar") { return url.openConnection().jarFile; }
|
||||||
|
@ -19,7 +19,7 @@ export class BukkitEvent extends event.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getJarFile(resource: string) {
|
getJarFile(resource: string) {
|
||||||
return super.getJarFile('org/bukkit/Bukkit.class')
|
return super.getJarFile('org/bukkit/Bukkit.class', Bukkit.class.classLoader)
|
||||||
}
|
}
|
||||||
isValidEvent(clazz: any): boolean {
|
isValidEvent(clazz: any): boolean {
|
||||||
// 继承于 org.bukkit.event.Event
|
// 继承于 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 { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
import * as reflect from '@ms/common/dist/reflect'
|
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: '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;
|
let Bukkit = org.bukkit.Bukkit;
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
@ -68,14 +61,24 @@ export class BukkitServer implements server.Server {
|
|||||||
|
|
||||||
private reflectPipeline() {
|
private reflectPipeline() {
|
||||||
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
||||||
|
let connection: any;
|
||||||
let promise: any;
|
let promise: any;
|
||||||
for (const ref of refList) {
|
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||||
try {
|
try {
|
||||||
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
connection = reflect.on(consoleServer).call(method).get()
|
||||||
} catch (error) {
|
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()
|
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 { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
import * as reflect from '@ms/common/dist/reflect'
|
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 File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
@ -64,14 +58,24 @@ export class SpongeServer implements server.Server {
|
|||||||
}
|
}
|
||||||
private reflectPipeline() {
|
private reflectPipeline() {
|
||||||
let consoleServer = reflect.on(Sponge.getServer()).get()
|
let consoleServer = reflect.on(Sponge.getServer()).get()
|
||||||
|
let connection: any;
|
||||||
let promise: any;
|
let promise: any;
|
||||||
for (const ref of refList) {
|
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||||
try {
|
try {
|
||||||
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
connection = reflect.on(consoleServer).call(method).get()
|
||||||
} catch (error) {
|
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()
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user