Solved AsyncPlayerChat e.setCancelled(true); issues

Discussion in 'Spigot Plugin Development' started by Discommend, Jun 25, 2016.

  1. @EventHandler(priority = EventPriority.HIGHEST)
    public void onChat(AsyncPlayerChatEvent e)
    Player p = e.getPlayer();
    for(Player all : Bukkit.getServer().getOnlinePlayers())
    all.sendMessage(Prefix1 + " " + p.getName() +ChatColor.DARK_GRAY + " | " + ChatColor.AQUA + e.getMessage());
    all.sendMessage(Prefix1 + " " + p.getName() + ChatColor.DARK_GRAY + " | " + ChatColor.AQUA + e.getMessage());

    I've tried many different things to fix these problem none seem to be working.
  2. What errors are you exactly getting and what lines are they on?
  3. The error is the e.setCancelled(true); it's not registering in game so when ever someone is in the staff chat players can still see there messages as if they were not in staff chat at all
  4. Are all of the online players receiving this message? all.sendMessage(Prefix1 + " " + p.getName() +ChatColor.DARK_GRAY + " | " + ChatColor.AQUA + e.getMessage());
    If not it, this part of your code obviously is not being called. It is most likely because you are trying to check if 'list' contains all of the online players. Try adding debug messages when you run into stuff like this just incase the codes isn't actually being called.
  5. They are it's just not blocking there chat say if they can do /sc? but it doesn't block there chat out they're able to talk in staff chat but a message also sends as if there just typing in regular minecraft chat
  6. Because I'm sure not both their name and player object is contained in the same list. Moreover, you should cancel as soon as they're in the list (not cancel each time you find a player who's in the list).

    Lastly, use Sets, not Lists, they're faster for contains checks.
  7. I fixed it thanks for the help everyone [Solved]