feat: update plugin & websocket
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
b67474f7ff
commit
f40eddd5e3
@ -2,9 +2,9 @@
|
||||
/// <reference types="@ms/types/dist/typings/sponge" />
|
||||
/// <reference types="@ms/types/dist/typings/bungee" />
|
||||
|
||||
import { server, plugin as pluginApi, channel } from '@ms/api'
|
||||
import { server, plugin as pluginApi, channel, constants } from '@ms/api'
|
||||
import { inject, optional } from '@ms/container';
|
||||
import { plugin, interfaces, cmd, listener, tab, config } from '@ms/plugin'
|
||||
import { plugin, interfaces, cmd, listener, tab, config, enable } from '@ms/plugin'
|
||||
import Tellraw from '@ms/common/dist/tellraw'
|
||||
|
||||
const ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream");
|
||||
@ -12,10 +12,8 @@ const ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream");
|
||||
const StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
|
||||
const GZIPInputStream = Java.type("java.util.zip.GZIPInputStream");
|
||||
const GZIPOutputStream = Java.type("java.util.zip.GZIPOutputStream");
|
||||
const Consumer = Java.type("java.util.function.Consumer");
|
||||
const ByteArray = Java.type("byte[]")
|
||||
|
||||
const BiConsumer = Java.type('java.util.function.BiConsumer')
|
||||
const ByteArray = Java.type("byte[]")
|
||||
|
||||
class MiaoMessage {
|
||||
// public static final String CHANNEL = "MiaoChat:Default".toLowerCase();
|
||||
@ -146,7 +144,7 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
}
|
||||
|
||||
private compare(prop: string) {
|
||||
return function(obj1: { [x: string]: any; }, obj2: { [x: string]: any; }) {
|
||||
return function (obj1: { [x: string]: any; }, obj2: { [x: string]: any; }) {
|
||||
var val1 = obj1[prop];
|
||||
var val2 = obj2[prop];
|
||||
if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
|
||||
@ -184,9 +182,6 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
} catch (ex) {
|
||||
this.logger.console("§cCan't found me.clip.placeholderapi.PlaceholderAPI variable will not be replaced! Err: " + ex)
|
||||
}
|
||||
this.channelOff = this.Channel?.listen(this, MiaoMessage.CHANNEL, (data) => {
|
||||
this.sendChatAll(MiaoMessage.decode(data).json)
|
||||
})
|
||||
}
|
||||
|
||||
spongeenable() {
|
||||
@ -205,6 +200,10 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
} catch (ex) {
|
||||
this.logger.console("§cCan't found me.rojo8399.placeholderapi.PlaceholderService variable will not be replaced! Err: " + ex)
|
||||
}
|
||||
}
|
||||
|
||||
@enable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
|
||||
serverEnbale() {
|
||||
this.channelOff = this.Channel?.listen(this, MiaoMessage.CHANNEL, (data) => {
|
||||
this.sendChatAll(MiaoMessage.decode(data).json)
|
||||
})
|
||||
@ -244,7 +243,7 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
|
||||
@listener({ servers: ['bukkit'] })
|
||||
AsyncPlayerChatEvent(event: org.bukkit.event.player.AsyncPlayerChatEvent) {
|
||||
this.sendChat(event.getPlayer(), event.getMessage(), function() {
|
||||
this.sendChat(event.getPlayer(), event.getMessage(), function () {
|
||||
event.setCancelled(true);
|
||||
});
|
||||
}
|
||||
@ -260,7 +259,7 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
if (plain.startsWith(Tellraw.duplicateChar)) {
|
||||
return;
|
||||
}
|
||||
this.sendChat(player, plain, function() {
|
||||
this.sendChat(player, plain, function () {
|
||||
event.setMessageCancelled(true)
|
||||
});
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ import { plugin, interfaces, cmd } from '@ms/plugin'
|
||||
import { inject, ContainerInstance, Container } from '@ms/container'
|
||||
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ms/websocket'
|
||||
|
||||
const suffixMap = {
|
||||
ts: 'typescript',
|
||||
js: 'javascript',
|
||||
yml: 'yaml'
|
||||
}
|
||||
|
||||
@plugin({ name: 'MiaoConsole', version: '1.0.0', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
|
||||
export class MiaoConsole extends interfaces.Plugin {
|
||||
@inject(ContainerInstance)
|
||||
@ -84,7 +90,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
}
|
||||
})
|
||||
client.on('edit', (file: string, fn) => {
|
||||
fn && fn(base.read(file), file.split('.', 2)[1])
|
||||
fn && fn(base.read(file), suffixMap[file.split('.', 2)[1]])
|
||||
})
|
||||
client.on('disconnect', () => {
|
||||
this.logger.console(`§6客户端 §b${client.id} §c断开连接...`)
|
||||
@ -93,16 +99,16 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
this.logger.info('Netty Channel Pipeline Inject MiaoDetectHandler Successful!')
|
||||
}
|
||||
|
||||
private runCode(code: string, namespace, client) {
|
||||
private runCode(code: string, namespace: any, client: any) {
|
||||
let tfunc = new Function('namespace', 'client', `
|
||||
var reflect = require('@ms/common/dist/reflect');
|
||||
var tempconcent = '';
|
||||
function print(text) {
|
||||
tempconcent += "\\n" + text
|
||||
tempconcent += text + "\\n"
|
||||
}
|
||||
return eval(${JSON.stringify(code)}) + tempconcent
|
||||
var result = eval(${JSON.stringify(code)});
|
||||
return tempconcent + result
|
||||
`)
|
||||
console.log(tfunc)
|
||||
return this.task.callSyncMethod(() => tfunc.apply(this, [namespace, client])) + ''
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": false,
|
||||
"inlineSourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
import { NettyClient } from './client'
|
||||
import { ServerOptions } from '../socket-io'
|
||||
import { ServerEvent, Keys } from './constants'
|
||||
import { WebSocketDetect } from './websocket_detect'
|
||||
import { WebSocketHandler } from './websocket_handler'
|
||||
import { NettyClient } from './client'
|
||||
import { ServerOptions } from '../socket-io'
|
||||
|
||||
class NettyWebSocketServer extends EventEmitter {
|
||||
private pipeline: any;
|
||||
@ -22,10 +22,9 @@ class NettyWebSocketServer extends EventEmitter {
|
||||
ctx.fireChannelRead(channel)
|
||||
})
|
||||
connectEvent.on(ServerEvent.connect, (ctx) => {
|
||||
console.log('NettyWebSocketServer ServerEvent.connect', ctx, ctx.channel().id(), ctx.channel().class.name)
|
||||
let nettyClient = new NettyClient(this, ctx.channel());
|
||||
this.allClients[nettyClient.id] = nettyClient;
|
||||
this.emit(ServerEvent.connect, nettyClient);
|
||||
let nettyClient = new NettyClient(this, ctx.channel())
|
||||
this.allClients[nettyClient.id] = nettyClient
|
||||
this.emit(ServerEvent.connect, nettyClient)
|
||||
})
|
||||
connectEvent.on(ServerEvent.message, (ctx, msg) => {
|
||||
this.emit(ServerEvent.message, this.allClients[ctx.channel().id()], msg.text())
|
||||
@ -46,4 +45,4 @@ export {
|
||||
NettyWebSocketServer,
|
||||
ServerEvent,
|
||||
NettyClient
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { TextWebSocketFrameHandlerAdapter } from '../netty'
|
||||
import { EventEmitter } from 'events'
|
||||
import { ServerEvent } from './constants'
|
||||
import { ServerOptions } from '../socket-io';
|
||||
import { TextWebSocketFrameHandlerAdapter } from '../netty'
|
||||
|
||||
export class TextWebSocketFrameHandler extends TextWebSocketFrameHandlerAdapter {
|
||||
private event: EventEmitter;
|
||||
|
Loading…
Reference in New Issue
Block a user