Plugin Messages not working

Discussion in 'BungeeCord Plugin Development' started by TGlev, May 29, 2015.

  1. Hello,

    I started working with Plugin Messages today. I got a small problem though. Whenever I try to send a plugin message in code, it doesn't do anything. But when I force shutdown the server (Just clicking the cross), it suddenly is sended to the other server. When I type /stop in the console, nothing happens.

    My code:
    Code (Text):
    public class Main extends JavaPlugin implements PluginMessageListener, Listener{

        String channelName = "BungeeCord";
        final JavaPlugin instance = this;

        public void onEnable(){
            //this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");

            this.getServer().getMessenger().registerOutgoingPluginChannel(this, channelName);
            this.getServer().getMessenger().registerIncomingPluginChannel(this, channelName, this);
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("pms")){

                 ByteArrayDataOutput out = ByteStreams.newDataOutput();
                 out.writeUTF("Forward");
                 out.writeUTF("serv2");
                 out.writeUTF("test");      
                 byte[] data = "TEST".getBytes();
                 out.writeShort(data.length);
                 out.write(data);
                 this.getServer().sendPluginMessage(this, "BungeeCord", out.toByteArray());

            }
            return true;
        }
    I got a tiny plugin on the other side which broadcasts all recieved messages, I know this works because when I join the server using the BungeeCord command, I see the message getting broadcasted.

    EDIT: Posted in wrong forum, meant to post in the bungeecord section. I already reported the post myself.
     
    #1 TGlev, May 29, 2015
    Last edited: May 29, 2015
  2. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    Thread moved => BungeeCord Plugin Development