Solved Anti-Swearing plugin problem (Error: Asynchronous player kick!)

Discussion in 'Plugin Development' started by UNC00KED, Aug 30, 2015.

Thread Status:
Not open for further replies.
  1. Hello. I am creating an Anti-Swearing plugin and have come to a problem when trying to tempban the player. Whenever the player joins the server, their warnings is automatically set to 0. Then, if they say a swear word, their warning increments. And if they have sweared at least 3 times, then they will automatically be tempbanned from the server, supposedly. The problem is, whenever I try to dispatch a console command tempbanning the player, I get an error, in console, saying, "Asynchronous player kick!". Should I be using a different event or something, or am I just doing something simple, wrong? I would appreciate any help. Thanks!

    Code:
        @EventHandler
        public void joinEvent (PlayerJoinEvent event) {
         
            Player player = event.getPlayer();
         
            BadWords.playerWarnings.put(player.getUniqueId(), 0);
         
        }
     
        @EventHandler
        public void chatEvent (AsyncPlayerChatEvent event) {
         
            Player player = event.getPlayer();
            String playerMsg = event.getMessage();
            String s = "";
            int number = BadWords.playerWarnings.get(player.getUniqueId());
         
            if (BadWords.badWords.size() != 0) {
             
                for (int i=0; i < BadWords.badWords.size(); i++) {
                 
                    s = BadWords.badWords.get(i);
                    if (playerMsg.toLowerCase().contains(s.toLowerCase())) {
                     
                        if (number >= 3) {
                            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tempban " + player.getName() + " 10sec Inappropriate Language");
                        }
                        number++;
                        player.sendMessage(ChatColor.RED + "Watch your language!");
                        BadWords.playerWarnings.put(player.getUniqueId(), number);
                        event.setCancelled(true);
                     
                    }
                 
                }
             
            }
         
        }
    [​IMG]
     
    Last edited: Aug 30, 2015
  2. Offline

    mythbusterma

    @UNC00KED

    Use the deprecated PlayerChatEvent instead. It was a mistake of the Bukkit team to deprecate it in favour of the AsyncPlayerChatEvent, since nobody actually understands asynchronous programming.
     
  3. Sounds good. Thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page