package io.github.lasercar.simplemention;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleMention extends JavaPlugin implements Listener {

    //init

    String format_mention;
    String format_default;

    public void onEnable() {
        saveDefaultConfig();
        getConfig().options().copyDefaults(true);
        saveConfig();

        format_mention = getConfig().getString("format-mention");
        format_default = getConfig().getString("format-default");

        getServer().getPluginManager().registerEvents(this, this);
    }

    //events

    @EventHandler
    public void onChat(AsyncPlayerChatEvent event) {
        String message = event.getMessage();

        if (message.contains("@")) {
            Player player = event.getPlayer();
            Collection onlinePlayers = Bukkit.getOnlinePlayers();

            Pattern pattern = Pattern.compile("(@\\w+)");
            //make this^ looser and move checking to later if adding @/group formats
            Matcher matcher = pattern.matcher(message);

            while (matcher.find()) {
                getLogger().info(matcher.group(1));
            }

            //for @ matches, replace and ping

//            event.setMessage(modifiedMessage);
        }
    }

}

@@ -292,16 +292,65 @@
 ection;%0A
+import java.util.HashMap;%0Aimport java.util.List;%0A
 import j
@@ -404,16 +404,52 @@
 Pattern;
+%0Aimport java.util.stream.Collectors;
 %0A%0Apublic
@@ -536,26 +536,25 @@
 tring format
-_m
+M
 ention;%0A    
@@ -562,26 +562,25 @@
 tring format
-_d
+D
 efault;%0A%0A   
@@ -725,10 +725,9 @@
 rmat
-_m
+M
 enti
@@ -790,10 +790,9 @@
 rmat
-_d
+D
 efau
@@ -1041,16 +1041,73 @@
 ssage();
+%0A        StringBuffer messageBuffer = new StringBuffer();
 %0A%0A      
@@ -1211,15 +1211,9 @@
 ion 
-onlineP
+p
 laye
@@ -1307,93 +1307,8 @@
 %22);%0A
-            //make this%5E looser and move checking to later if adding @/group formats%0A
     
@@ -1417,44 +1417,185 @@
     
-getLogger().info(matcher.group(1
+String match = matcher.group(1);%0A%0A                Collection found = players.stream().filter(p -%3E p.getPlayerListName().contains(match) %7C%7C p.getDisplayName().contains(match
 ));%0A
+%0A
     
@@ -1606,56 +1606,241 @@
     
-%7D%0A%0A            //for @ matches, replace and ping
+    //TODO: partial matching of display name and username%0A                //TODO: only highlight mentions if found (prefix formatMention and suffix formatDefault)%0A%0A                //TODO: ping matched players with sound%0A            %7D
 %0A%0A//
@@ -1873,22 +1873,31 @@
 ge(m
-odifiedMessage
+essageBuffer.toString()
 );%0A 

Add WIP player filtering by match