package de.viper.survivalplus.listeners;

import de.viper.survivalplus.Manager.BlockManager;
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;

public class ChatBlockListener implements Listener {

    private final BlockManager blockManager;

    public ChatBlockListener(BlockManager blockManager) {
        this.blockManager = blockManager;
    }

    @EventHandler
    public void onChat(AsyncPlayerChatEvent event) {
        Player sender = event.getPlayer();

        event.getRecipients().removeIf(recipient ->
            blockManager.hasBlocked(recipient, sender) || blockManager.hasBlocked(sender, recipient)
        );
    }
}
