Solved Plugin Messages Not Received

Discussion in 'Spigot Plugin Development' started by JDBL, Jun 16, 2018.

  1. Hi, I am quite new to working with Bungee and have not been able to send plugin messages successfully. I have BungeeCord setup properly as well as servers connected together. No error messages are sent and it simply seems that the "onPluginMessageReceived" event is not firing. Any help regarding the issue would be greatly appreciated.

    Code (Java):
    public class Test
            extends JavaPlugin
            implements PluginMessageListener, Listener
    {
        private List<String> serverList = new ArrayList<>();

        @Override
        public void onEnable()
        {
            getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this::onPluginMessageReceived);

            getServer().getPluginManager().registerEvents(this, this);
        }

        @Override
        public synchronized void onPluginMessageReceived(String channel, Player player, byte[] message)
        {
            if (!channel.equalsIgnoreCase("BungeeCord")) return;

            ByteArrayDataInput in = ByteStreams.newDataInput(message);
            String subchannel = in.readUTF();

            if (subchannel.equalsIgnoreCase("GetServers"))
            {
                String[] serverList = in.readUTF().split(", ");

                Collections.addAll(this.serverList, serverList);
            }
        }

        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e)
        {
            Player player = e.getPlayer();

            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("GetServers");
            player.sendPluginMessage(this, "BungeeCord", out.toByteArray());

            player.sendMessage(serverList.toString());
        }
    }
    Thanks in advance,

    James
     
  2. I have the same problem, can someone explain how to fix this?