Player Count

Discussion in 'BungeeCord Plugin Development' started by DisCoder212, Mar 20, 2017.

  1. Hey, I posted this on Spigot Plugin Development first but they said to transfer over here.

    This is a use of SpigotAPI with messaging channels to connect with bungee

    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)

Share This Page