Team Chat problems

Discussion in 'Plugin Development' started by Splated, Nov 29, 2012.

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

    Splated

    Im trying to make a simple mod that filters all chat messages to just team members.

    Code:
       
        @EventHandler (priority = EventPriority.LOW)
        public void onPlayerChatEvent(AsyncPlayerChatEvent event) {
            if (RunningMod == null) return;
           
            Team team = RunningMod.getTM().GetTeam(event.getPlayer());
           
           
            Set<Player> players = event.getRecipients();
           
            for (Player p:players){
                if (!RunningMod.getTM().GetTeam(p).equals(team))
                    p.remove();
               
            }
           
            //team.getColor()
           
            event.setMessage("["+team.getTeamName()+"] "+event.getMessage());
        }
       
       
        


    In my small tests it worked but on a bigger server it locked up. i think when a player disconnected is when the problem happened.
     
  2. Offline

    phondeux

    I would check to make sure a player isn't null before sending.
     
  3. Offline

    fireblast709

    phondeux that would throw a NPE
    Splated Do not call any Bukkit methods (unless declared thread-safe), as the event is async when it is called as players send chat messages.
     
  4. Offline

    Splated

    if i made the GetTeam synchronized would that fix it?
     
Thread Status:
Not open for further replies.

Share This Page