Disable chat for player

Discussion in 'Plugin Development' started by Faith, Mar 19, 2015.

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

    Faith

    How can I disable all chat for a player without a permission?

    EDIT: So they can't type anything or see what others are typing.
     
  2. Offline

    sgavster

    @Faith Well, to cancel the chat I would do AsyncPlayerChatEvent, and check if the player has permission.. But to cancel them seeing the messages I would probably take the same event, cancel it, then message all the players that can see it with for(Player onlinePlayer : Bukkit.getOnlinePlayers()) { if(onlinePlayer.hasPermission(...) { onlinePlayer.sendMessage(event.getMessage()); ect.. I did this without an IDE, so let me know if this works..
     
  3. Offline

    mttprvst13

    You could put this in a Chat Listener:
    Code:
    e.getRecipients().clear();
    List<Player> recipients = new LinkedList<Player>();
    for( Player p : plugin.getServer().getOnlinePlayers()){
       
        if(!pluign.getIsMuted(p)){
           
            recipients.add(p);
           
        }
       
    }
    if(!plugin.getIsMuted(player)){
        e.getRecipients().addAll(regipients);
    }else{
        
        e.getRecipients().clear();
        
    }
    
    Where player is the player's instance e is the event, plugin is your main classes instance and getIsMuted checks to see if the player is muted. I do not believe there is a way to take away the user's chat ability but this makes it to where they do not recive any messages from other players and there messages do not get to other players.
     
  4. Offline

    teej107

    @Faith To stop a player from chatting, cancel the event. To keep a player from seeing a message, remove him from the recipient Set.
     
Thread Status:
Not open for further replies.

Share This Page