Disabling chat for a player

Discussion in 'Plugin Development' started by javoris767, Jun 20, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    javoris767

    Hello, I need to know how to disable chat for a player like the buycraft command /buy does.
     
  2. Just remove the player from the recipients set at the player chat event.
     
  3. Offline

    mfran2016

    its easy just insert this code in a listener
    Code:
    @EventHandler
    public void onChat(PlayerChatEvent e)
    {
        if(e.getPlayer().getName().equalsIgnoreCase("player's name")
        {
            e.setCancelled(true);
        }
    }
     
  4. Offline

    ZachBora

    Depends if you want the player to be unable to speak or unable to listen or both.

    If you want the player to not see the chat, you do it like so :
    public void onPlayerChat(PlayerChatEvent event)
    {
    [...]
    event.getRecipients().remove(player);
    }

    If you want the player to be unable to chat, you do it like so :
    public void onPlayerChat(PlayerChatEvent event)
    {
    if(event.getPlayer().getName().equalsIgnoreCase("name"))
    event.setCancelled(true);
    }
     
Thread Status:
Not open for further replies.

Share This Page