Bungee Messaging Channel HELP

Discussion in 'Spigot Plugin Development' started by DisCoder212, Mar 19, 2017.

  1. So basically I have this set in my main class:

    Code (Text):

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

    public void onPluginMessageReceived(String channel, Player player, byte[] message) {
        if (!channel.equals("BungeeCord")) {
        ByteArrayDataInput in = ByteStreams.newDataInput(message);
        String subchannel = in.readUTF();
        if (subchannel.equals("PlayerCount")) {

            String server = in.readUTF();
            int playercount = in.readInt();

            getPlayerCount.playercount = playercount;
            getPlayerCount.server = server;

    And I have my class to get the player count:

    Code (Text):

    public class getPlayerCount {

        public static String server;
        public static int playercount;

        public static int getServerPlayerCount(String servername, Player player){

            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);

            try {
                player.sendPluginMessage(Main.getPlugin(), "BungeeCord", b.toByteArray());
            } catch (Exception e1) {
            return playercount;
    For some reason this doesn't get the player count, I tried many things but I still can't seem to get this to work. And this is posted under spigot development because this is still the SpigotMCAPI just using Bungee Messaging to connect with bungee(for anyone who says this should be posted on bungee development)
  2. It should be a method of your main class rather than another class.
    Because you registered your main as outgoing Messaging channel:
    Furthermore, when do you call #getServerPlayerCount? Also remember, you could use "ALL" as servername to get the total amount of players.
  3. Sorry for the late reply, I put this on my main class and it still doesn't seem to be working. and I call #getServerPlayerCount when a player opens a GUI which places an item and on the item it shows the number of player's on that specific server
  4. This isn't bungeecord though technically, since I am using SpigotAPI. This is just a message channel to connect within bungee but I'll just give it ago anyways thanks
    • Like Like x 1
  5. Does your listener class implement the "PluginMessageListener" interface?
    If so, print out the complete bytearray "message" to the console right at the begin of "#onPluginMessageReceived" before any checks or returns to see if it event gets called and if the subchannel matches.

    Furthermore you should follow the naming conventions given by Oracle: https://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html

Share This Page