feat: add channel support for bungee bukkit sponge
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
28
packages/bukkit/src/channel.ts
Normal file
28
packages/bukkit/src/channel.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { channel, plugin } from '@ms/api'
|
||||
import { inject, injectable } from '@ms/container'
|
||||
|
||||
const Bukkit = org.bukkit.Bukkit
|
||||
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
||||
const Messenger = Bukkit.getMessenger()
|
||||
|
||||
@injectable()
|
||||
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({
|
||||
onPluginMessageReceived: (/**String */ var1, /**Player */ var2, /**byte[] */var3) => {
|
||||
listener(var3)
|
||||
}
|
||||
}));
|
||||
Messenger.registerOutgoingPluginChannel(this.pluginInstance, channel);
|
||||
}
|
||||
unregister(channel: string, listener: any) {
|
||||
Messenger.unregisterIncomingPluginChannel(this.pluginInstance, channel)
|
||||
Messenger.unregisterOutgoingPluginChannel(this.pluginInstance, channel)
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
/// <reference types="@ms/types/dist/typings/bukkit" />
|
||||
|
||||
import { server, command, event, task } from '@ms/api'
|
||||
import { server, command, event, channel, task } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
import { BukkitConsole } from './console';
|
||||
import { BukkitEvent } from './event';
|
||||
import { BukkitServer } from './server';
|
||||
import { BukkitCommand } from './command';
|
||||
import { BukkitChannel } from './channel';
|
||||
import { BukkitTaskManager } from './task';
|
||||
|
||||
export default function BukkitImpl(container: Container) {
|
||||
@ -14,5 +15,6 @@ export default function BukkitImpl(container: Container) {
|
||||
container.bind(event.Event).to(BukkitEvent).inSingletonScope();
|
||||
container.bind(server.Server).to(BukkitServer).inSingletonScope();
|
||||
container.bind(command.Command).to(BukkitCommand).inSingletonScope();
|
||||
container.bind(channel.Channel).to(BukkitChannel).inSingletonScope();
|
||||
container.bind(task.TaskManager).to(BukkitTaskManager).inSingletonScope();
|
||||
}
|
||||
|
Reference in New Issue
Block a user