feat: channel add ext data

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-27 18:14:17 +08:00
parent 33d29271f9
commit 97877832c4
4 changed files with 14 additions and 7 deletions

View File

@ -5,7 +5,7 @@ export namespace channel {
* handle plugin message
* @param data byte[]
*/
export type ChannelListener = (data: any) => void
export type ChannelListener = (data: any, exts?: any) => void
@injectable()
export abstract class Channel {

View File

@ -15,8 +15,8 @@ export class BukkitChannel extends channel.Channel {
}
register(channel: string, listener: channel.ChannelListener) {
Messenger.registerIncomingPluginChannel(this.pluginInstance, channel, new PluginMessageListener({
onPluginMessageReceived: (/**String */ var1, /**Player */ var2, /**byte[] */var3) => {
listener(var3)
onPluginMessageReceived: (/**String */ channel, /**Player */ player, /**byte[] */data) => {
listener(data, { channel, player, data })
}
}));
Messenger.registerOutgoingPluginChannel(this.pluginInstance, channel);

View File

@ -1,18 +1,25 @@
import { channel } from '@ms/api'
import { provideSingleton } from '@ms/container'
import { channel, event } from '@ms/api'
import { provideSingleton, inject } from '@ms/container'
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
@provideSingleton(channel.Channel)
export class BungeeChannel extends channel.Channel {
@inject(event.Event)
private eventManager: event.Event;
send(player: any, channel: string, data: any) {
throw new Error("Method not implemented.");
}
register(channel: string, listener: channel.ChannelListener) {
Bungee.registerChannel(channel);
console.console('§6[§eWARN§6] §eBungeeCord Channel only registerChannel you need self hanler PluginMessageEvent!')
// console.console('§6[§eWARN§6] §eMiaoScript channel in BungeeCord only register. you need self hanler PluginMessageEvent!')
return this.eventManager.listen({ description: { name: channel } }, "PluginMessageEvent", (event: net.md_5.bungee.api.event.PluginMessageEvent) => {
listener(event.getData(), event)
})
}
unregister(channel: string, listener: any) {
Bungee.unregisterChannel(channel);
listener.off();
}
}

View File

@ -25,7 +25,7 @@ export class SpongeChannel extends channel.Channel {
}
let innerListener = new RawDataListener({
handlePayload: (/* ChannelBuf */ data: any, /**RemoteConnection */ connection: any, /**Platform.Type */ side: any) => {
listener(data.readBytes(data.available()))
listener(data.readBytes(data.available()), { data, connection, side })
}
})
this.channelMap.get(channel).addListener(innerListener);