3

I tried to send a message via the "BungeeCord Plugin Messaging Channel" from the Proxy to a Server. I used the following Code:

In the BungeeCord Plugin:

        ByteArrayOutputStream bb = new ByteArrayOutputStream();
        DataOutputStream outt = new DataOutputStream(bb);
        try {
            outt.writeUTF("Forward");
            outt.writeUTF("lobby");
            outt.writeUTF("anfrage ");
            outt.writeUTF(pp.getDisplayName());
        } catch (IOException e) {
            e.printStackTrace();
        }
        pp.sendData("GlobalSystem", bb.toByteArray());

In the Spigot Plugin:

public class MessageListener implements PluginMessageListener {

public MessageListener(main main) {
    plugin = main;
    plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, "GlobalSystem", this);
    plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "GlobalSystem");
}

@Override
public void onPluginMessageReceived(String channel, Player p, byte[] args) {
    System.out.println("hi");
}

main plugin = main.getPlugin();
}

What is wrong with it? I read everything on these websites:

PostCrafter.de

Bukkit & Bungee Plugin Message Channel

Sorry for my bad English and thanks for your help :)

LeWimbes
  • 517
  • 1
  • 10
  • 25
  • The code looks like it's right, whats `pp`? EDIT: Did you use messageListener(this) in your onEnable? – TxCraft Mar 16 '16 at 00:08
  • 'pp' is a 'ProxiedPlayer'... I made it work, but some messages were received two times, so now I try to develop something with 'Sockets' – LeWimbes Mar 16 '16 at 06:02

2 Answers2

3

You made another mistake. You are sending your packets to the player and not to the server. You need to do

pp.getServer().sendData("GlobalSystem", bb.toByteArray());
gyurix
  • 1,106
  • 9
  • 23
  • Oh that's right, I'm now using a Multicast, so there also don't has to be a player online if I want to send a message. – LeWimbes Apr 20 '16 at 05:17
0

In your Spigot plugin you should do

 plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this);
 plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");

Because the Spigot-BungeeCord communication works through the BungeeCord channel.

Read the https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/ page for more informations about the Spigot-BungeeCord communication.

gyurix
  • 1,106
  • 9
  • 23
  • Your are not 100% right: Of course you have to register the Channel in the 'onEnable()'. But you don't have to use the Channel 'BungeeCord'! You can also use other Channles, but then you have to register it in the BungeeCord plugin, too. Also you have to use your "own" messages. – LeWimbes Mar 20 '16 at 00:04
  • You need to use the BungeeCord channel, to communicate with BungeeCord. Have you read this? https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#the-bungeecord-plugin-channel – gyurix Mar 20 '16 at 09:21
  • Well, not if I only wan't to send Strings without Forward or something like that – LeWimbes Mar 21 '16 at 16:48