feat: MiaoConsole exclude nukkit

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-27 18:15:33 +08:00
parent e7d44af48c
commit 3f475a7dc1

View File

@ -16,7 +16,7 @@ const refList: Array<{ server: string, future: string }> = [
{ server: 'func_147137_ag', future: 'field_151274_e' }//catserver 1.12.2
]
@plugin({ name: 'MiaoConsole', version: '1.0.0', author: 'MiaoWoo', source: __filename })
@plugin({ name: 'MiaoConsole', version: '1.0.0', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
export class MiaoConsole extends interfaces.Plugin {
public static GlobalContainer: Container
public static GlobalLogger: Console
@ -98,6 +98,7 @@ export class MiaoConsole extends interfaces.Plugin {
}
injectMiaoDetect() {
let MiaoDetectHandler = getMiaoDetectHandler();
this.pipeline.addFirst('miao_detect', new MiaoDetectHandler())
this.container.bind(MessageHandle).toFunction(this.onmessage.bind(this))
this.logger.info('Netty Channel Pipeline Inject MiaoDetectHandler Successful!')
@ -132,13 +133,14 @@ export class MiaoConsole extends interfaces.Plugin {
}
sendResult(ctx: any, type: string, msg: string) {
let TextWebSocketFrame = getTextWebSocketFrame()
ctx.writeAndFlush(new TextWebSocketFrame(`${type}${SPLIT_LINE}${msg}`))
}
}
function getMiaoDetectHandler() {
const ChannelInboundHandlerAdapter = Java.type('io.netty.channel.ChannelInboundHandlerAdapter')
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
const MiaoDetectHandler = Java.extend(ChannelInboundHandlerAdapter, {
channelRead: (ctx: any, channel: any) => {
channel.pipeline().addFirst('miaowebsocket', new WebSocketHandler())
@ -240,3 +242,9 @@ const WebSocketHandler = Java.extend(ChannelInboundHandlerAdapter, {
ctx.fireChannelRead(msg)
}
})
return MiaoDetectHandler;
}
function getTextWebSocketFrame() {
return Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
}