[Solved] Canceling all chat events for single player.

Discussion in 'Spigot Plugin Development' started by EDMAN93, May 31, 2015.

  1. Hey, I am about to write a plugin that requires me to cancel all incoming and outgoing chat-messages of on single player.


    Someone on Google suggested to use :
    Code (Text):
    AsyncPlayerChatEvent /  event.getRecipients().remove(player);

    But I am not sure what exactly it does and why my player still receives server broadcasts and a login messages.

    Does anyone know how to do this?
     
  2. An AsyncPlayerChatEvent only applies to a player message. As in, it only registers messages sent by players, not by the server or plugins (console).
     
  3. You'll propably need to use something like protocollib if you want to block server messages xd
     
  4. You can listen for an outgoing chat packet with protocollib and cancel it, but you cant do it with just bukkit API
     
  5. Thanks. I managed to do it with ProtocolLib:


    Code (Text):
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(myPlugin, ListenerPriority.LOWEST, PacketType.Play.Server.CHAT) {
                @Override
                public void onPacketSending(PacketEvent event) {
                    if (event.getPacketType() == PacketType.Play.Server.CHAT) {
                        if (event.getPlayer() == myPlayer) {
                            event.setCancelled(true);
                        }
                    }
                }
            });
     
    #5 EDMAN93, Jun 1, 2015
    Last edited: Jun 1, 2015
    • Like Like x 3
  6. Awesome,! Now mark the post solved?