Disabling Chat Receiving

Discussion in 'Plugin Development' started by VenamousV, Jun 30, 2014.

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

    VenamousV

    I am attempting to make it so if a player can't receive/send chat unless it says he can in the config. This is what i have so far:
    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent event){
            Player player = (Player) event.getPlayer();
            for(Player players : Bukkit.getOnlinePlayers()){
                if(getplayerCfgFile().getBoolean("Players." + player.getName() + ".Can_Hear") == false){
                    event.getRecipients().remove(players);
                }
            }
        }
    It works to a point. The player can't send any chats, but he can still see chats from other players who have chatting enabled. Can anyone help me make it so only the players with chat disabled cant send or see chat from anyone but people with chat enabled can see chat from everyone else who has it enabled?
     
  2. Offline

    Garris0n

    1. Instead of checking "boolean == false", check "!boolean".
    2. You should be saving UUIDs, not names.
    3. That cast is completely redundant. AsyncPlayerChatEvent#getPlayer() returns a Player.
    4. You should not use a plural variable in a loop. It gives the false impression of the variable representing all players at once instead of each player sequentially.
    5. If you want to prevent players with that value in the config from receiving chat, why are you checking the config value for the player sending the chat?
     
  3. Offline

    VenamousV

    I have no clue what I'm doing there obviously, can you show me a simple way to make it work? Garris0n
     
  4. Offline

    Garris0n

    I specifically told you what was causing your problem, along with 4 other things you should fix.
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page