/** * Creates a new instance. * * @param source the source of the plugin message * @param target the destination of the plugin message * @param identifier the channel for this plugin message * @param data the payload of the plugin message */ public PluginMessageEvent(ChannelMessageSource source, ChannelMessageSink target, ChannelIdentifier identifier, byte[] data) { this.source = Preconditions.checkNotNull(source, "source"); this.target = Preconditions.checkNotNull(target, "target"); this.identifier = Preconditions.checkNotNull(identifier, "identifier"); this.data = Preconditions.checkNotNull(data, "data"); this.result = ForwardResult.forward(); }
@Override public boolean handle(PluginMessage packet) { if (!canForwardPluginMessage(packet)) { return true; } if (PluginMessageUtil.isMcBrand(packet)) { PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion()); serverConn.getPlayer().getMinecraftConnection().write(rewritten); return true; } if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { // Handled. return true; } ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel()); if (id == null) { return false; } MinecraftConnection clientConn = serverConn.getPlayer().getMinecraftConnection(); PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, packet.getData()); server.getEventManager().fire(event) .thenAcceptAsync(pme -> { if (pme.getResult().isAllowed() && !clientConn.isClosed()) { clientConn.write(packet); } }, clientConn.eventLoop()); return true; }
@Subscribe public void onPluginMessage(PluginMessageEvent e) { if (e.getIdentifier().equals(velocityChannelId)) { e.setResult(PluginMessageEvent.ForwardResult.handled()); } } }
@Subscribe public void onPluginMessage(PluginMessageEvent e) { if (e.getIdentifier().equals(velocityChannelId)) { e.setResult(PluginMessageEvent.ForwardResult.handled()); } } }