PluginMessageListener not working correctly

Discussion in 'BungeeCord Plugin Development' started by Hostadam1, Jul 28, 2018.

  1. I am attempting to make a check to see if a player connects using Forge, CheatBreaker or Vanilla Minecraft. However, whenever I start up the server it gives me "Attempted to register for a reserved channel name ('REGISTER')".

    Does anyone have any idea on how to fix this?

    Code (Java):
        @Override
        public void onEnable() {
            Bukkit.getMessenger().registerIncomingPluginChannel(this, "REGISTER", this);
        }
     

        @Override
        public void onPluginMessageReceived(String message, Player p, byte[] bytes) {
            switch(message) {
            case "REGISTER":
                ByteBuf buffer = Unpooled.copiedBuffer(bytes).copy();
                String buffer2 = buffer.toString(Charsets.UTF_8);
                try {
                    //method 1
                    for(int i = 0; i < buffer.capacity(); i++) {
                        byte b = buffer.getByte(i);
                        System.out.println((char) b);
                    }
                    //method 2
                    Bukkit.broadcastMessage(buffer2);
                }
                finally {
                    buffer.release();
                }
            }
        }

    EDIT: The error is on line 16 (Bukkit.getMessenger().registerIncomingPluginChannel(this, "REGISTER", this);)
     
  2. you just doing it wrong, you have to do something like that:
    Code (Text):

    @Override
    public void onPluginMessageReceived(String channel, Player player, byte[] value) {
      if (channel.equals("WDL|INIT") {
        //do something
      }
    }
     
    Code (Text):

    this.getServer().getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", this);
     
     
  3. Oh! Thank you sir!