package me.jne.AntiAd;

import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;

/**
 *
 * @author Franz
 */
public class ADListener implements Listener {

    private final AntiAd plugin;

    public ADListener(AntiAd plugin) {
        this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.NORMAL)
    public void onPlayerChat(AsyncPlayerChatEvent chat) {

        chat.setCancelled(plugin.getAdfinder().check(chat.getPlayer(), chat.getMessage(), 1,true));
    }

    @EventHandler(priority = EventPriority.LOW)
    public void onPlayerJoin(PlayerJoinEvent join) {
        if (plugin.getConfig().getBoolean("JoinMsg-On")) {
            join.getPlayer().sendMessage(ChatColor.YELLOW + "Running" + ChatColor.GREEN + " AntiAd" + ChatColor.YELLOW + ", Developed by XxCoolGamesxX and KasperFranz.");
        }
    }

    @EventHandler(priority = EventPriority.NORMAL)
    public void onSignCreation(SignChangeEvent sign) {

        for (int i = 0; i < sign.getLines().length; i++) {

            if (plugin.getAdfinder().check(sign.getPlayer(), sign.getLine(i), 3, false)) {
                i = sign.getLines().length;
                sign.setCancelled(true);
                sign.getBlock().breakNaturally();
            }
        }
    }

    @EventHandler(priority = EventPriority.NORMAL)
    public void onCommandSent(PlayerCommandPreprocessEvent chat) {


        String CL = chat.getMessage().split("\\s+")[0];
        List<String> Commands = plugin.getConfig().getStringList("Detected-Commands");
        if (Commands.contains(CL)) {
            chat.setCancelled(plugin.getAdfinder().check(chat.getPlayer(), chat.getMessage(), 2,true));
        }
    }
}

@@ -610,38 +610,39 @@
 = EventPriority.
-NORMAL
+HIGHEST
 )%0A    public voi
@@ -685,25 +685,24 @@
 chat) %7B%0A
-%0A
         
 chat.set
@@ -693,33 +693,18 @@
         
-chat.setCancelled
+if
 (plugin.
@@ -764,25 +764,81 @@
 (), 1,true))
-;
+%7B%0A        chat.setCancelled(true);    %0A        %7D%0A        
 %0A    %7D%0A%0A    

Fix for faction problem with double chat.