Incoming plugin channel not working

Discussion in 'BungeeCord Plugin Development' started by Pyshicon, Apr 29, 2019.

  1. Hello, so I got some problem where I sent from bukkit to bungee, it works. But the other way around, it doesn't.

    Here is the Main.class

    Code (Java):
    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new IsBannedChannel());

            Bukkit.getPluginCommand("test").setExecutor(new TestCommand());
        }
    }
     
    Here is the command I use to test send onto bukkit

    Code (Java):
    public class PurgatoryJoinCommand extends Command {

        public PurgatoryJoinCommand() {
            super("purgatory");
        }

        @Override
        public void execute(CommandSender sender, String[] args) {
            Channel.send((ProxiedPlayer) sender, "IsBanned", "hi");
        }
    }
     
    Here is how I send a plugin message from bungee to bukkit:

    Code (Java):
        public static void send(ProxiedPlayer player, String subchannel, String... message) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(stream);

            try {
                out.writeUTF(subchannel);

                for (String m : message) {
                    out.writeUTF(m);
                    System.out.println("SENT TO SPIGOT | " + m);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            player.sendData("BungeeCord", stream.toByteArray());
        }

    Here is how I listen to a channel on bukkit

    Code (Java):
    public class IsBannedChannel implements PluginMessageListener {

        private String c = "IsBanned";

        @Override
        public void onPluginMessageReceived(String channel, Player player, byte[] message) {
            DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));

            try {
                String subchannel = in.readUTF();
                System.out.println("BASIC RECEIVE");

                if (subchannel.equals(c)) {

                    String uuid = in.readUTF();
                    String state = String.valueOf(Database.get().isPlayerBanned(UUID.fromString(uuid), null));
                    System.out.println("RECEIVED FROM BUNGEE" + " | " + uuid + " | " + state);
                    Thread thread = new Thread(() -> Channel.send(Bukkit.getPlayer(UUID.fromString(uuid)), channel, uuid, state));
                    thread.start();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
     
    Thats all the information there is, any help would be appreciated. Thank you