Sending a PluginMessage from BungeeCord to a SpigotServer

LeWimbes picture LeWimbes · Dec 19, 2015 · Viewed 7.7k times · Source

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 :)

Answer

gyurix picture gyurix · Apr 16, 2016

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());