2020-05-02 16:14:47 +00:00
|
|
|
import { channel, plugin } from '@ccms/api'
|
|
|
|
import { inject, provideSingleton } from '@ccms/container'
|
2020-02-24 10:36:08 +00:00
|
|
|
|
|
|
|
const Bukkit = org.bukkit.Bukkit
|
|
|
|
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
|
|
|
const Messenger = Bukkit.getMessenger()
|
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(channel.Channel)
|
2020-02-24 10:36:08 +00:00
|
|
|
export class BukkitChannel extends channel.Channel {
|
|
|
|
@inject(plugin.PluginInstance)
|
|
|
|
private pluginInstance: any;
|
|
|
|
|
|
|
|
send(player: any, channel: string, data: any) {
|
|
|
|
player.sendPluginMessage(this.pluginInstance, channel, data);
|
|
|
|
}
|
|
|
|
register(channel: string, listener: channel.ChannelListener) {
|
|
|
|
Messenger.registerIncomingPluginChannel(this.pluginInstance, channel, new PluginMessageListener({
|
2020-02-27 10:14:17 +00:00
|
|
|
onPluginMessageReceived: (/**String */ channel, /**Player */ player, /**byte[] */data) => {
|
|
|
|
listener(data, { channel, player, data })
|
2020-02-24 10:36:08 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
Messenger.registerOutgoingPluginChannel(this.pluginInstance, channel);
|
|
|
|
}
|
|
|
|
unregister(channel: string, listener: any) {
|
|
|
|
Messenger.unregisterIncomingPluginChannel(this.pluginInstance, channel)
|
|
|
|
Messenger.unregisterOutgoingPluginChannel(this.pluginInstance, channel)
|
|
|
|
}
|
|
|
|
}
|