diff --git a/packages/api/src/channel.ts b/packages/api/src/channel.ts index 87100a9d..dca15a42 100644 --- a/packages/api/src/channel.ts +++ b/packages/api/src/channel.ts @@ -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 { diff --git a/packages/bukkit/src/channel.ts b/packages/bukkit/src/channel.ts index e92c679c..208c6c9a 100644 --- a/packages/bukkit/src/channel.ts +++ b/packages/bukkit/src/channel.ts @@ -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); diff --git a/packages/bungee/src/channel.ts b/packages/bungee/src/channel.ts index 04685079..a8ab5347 100644 --- a/packages/bungee/src/channel.ts +++ b/packages/bungee/src/channel.ts @@ -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(); } } diff --git a/packages/sponge/src/channel.ts b/packages/sponge/src/channel.ts index 87fc5063..c4f1f3b5 100644 --- a/packages/sponge/src/channel.ts +++ b/packages/sponge/src/channel.ts @@ -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);