package nl.dykam.dev.spector;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.*;

public class ShieldListener implements Listener {
    private final SpectorManager manager;

    public ShieldListener(SpectorManager manager) {
        this.manager = manager;
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onPlayerInteract(PlayerInteractEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canInteract())
            event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canInteract())
            event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onBlockBreak(BlockBreakEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canInteract())
            event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
        /*if (event.getEntity() instanceof Player) {
            SpectorShield shield = manager.getSpector((Player) event.getEntity()).getShield();
            if(shield.isInvincible())
                event.setCancelled(true);
        } else */if (event.getDamager() instanceof Player) {
            SpectorShield shield = manager.getSpector((Player) event.getDamager()).getShield();
            if(shield.isPeaceful())
                event.setCancelled(true);
        }
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onEntityDamage(EntityDamageEvent event) {
        if (event.getEntity() instanceof Player) {
            SpectorShield shield = manager.getSpector((Player) event.getEntity()).getShield();
            if(shield.isInvincible())
                event.setCancelled(true);
        }
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
        if(event.getTarget() instanceof Player) {
            SpectorShield shield = manager.getSpector((Player) event.getTarget()).getShield();
            if(!shield.isTargetable())
                event.setCancelled(true);
        }
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canChat())
            event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onAsyncPlayerChat(PlayerPickupItemEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canPickup())
            event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onPlayerDeath(PlayerDeathEvent event) {
        SpectorShield shield = manager.getSpector(event.getEntity()).getShield();
        if(!shield.canDrop())
            event.getDrops().clear();
    }

    @EventHandler(priority = EventPriority.LOWEST)
    private void onPlayerDropItem(PlayerDropItemEvent event) {
        SpectorShield shield = manager.getSpector(event.getPlayer()).getShield();
        if(!shield.canDrop())
            event.setCancelled(true);
    }
}

@@ -24,16 +24,45 @@
 ector;%0A%0A
+import org.bukkit.ChatColor;%0A
 import o
@@ -3345,17 +3345,17 @@
 .can
-Pickup
+Chat
 ())
+ %7B
 %0A   
@@ -3381,32 +3381,148 @@
 ancelled(true);%0A
+            event.getPlayer().sendMessage(ChatColor.RED + %22Chat is disabled currently disabled for you%22);%0A        %7D%0A
     %7D%0A%0A    @Even

Fix Shield Chat blocking