Solved Command not recognized by server

Discussion in 'BungeeCord Plugin Development' started by pairofsnipers, Apr 28, 2017.

  1. Title says it all

    Here is the code:
    Code (Text):
    public class BungeeCount extends JavaPlugin implements PluginMessageListener {

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

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

            try {
                DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
                String command = in.readUTF();

                if (command.equals("PlayerCount")) {
                    String server = in.readUTF();
                    int playerCount = in.readInt();

                    System.out.println("Server " + server + " has " + playerCount + " player(s).");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("bungeecount")) {
                String server = "ALL";

                if (args.length > 0) {
                    server = args[0];
                }

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

                    out.writeUTF("PlayerCount");
                    out.writeUTF(server);

                    Bukkit.getServer().sendPluginMessage(this, "BungeeCord", b.toByteArray());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            return true;
        }
    }
    Here is plugin.yml
    Code (Text):
    name: BungeeCount
    author: DawnMC
    main: org.nextmc.bungeecount.BungeeCount
    version: 1.0
    Not getting an error just when I try the command it doesn't recognize it as a registered command.
     
  2. electronicboy

    IRC Staff

    You've not registered the command in your plugin.yml
     
  3. This is what your plugin.yml should look like.

    Code (Text):
    name: BungeeCount
    author: DawnMC
    main: org.nextmc.bungeecount.BungeeCount
    version: 1.0
    commands:
      commandhere:
        description: some description for your command
     
  4. @electronicboy @Max604 ok I've done that now whenever I use the command all it does is give me the 'usage' and doesn't do anything else.
     
  5. Put a simple check at the start of the command to see if it runs at all.
     
  6. Fixed it, for whatever reason the auto import decided to import the wrong CommandSender so the onCommand method was never running. Thanks for the help guys.