package me.TahaCheji.Mafana.AquaDungeon;

import SkeletonHills.Apolo;
import me.TahaCheji.Mafana.Main;
import me.TahaCheji.Mafana.items.Armor;
import me.TahaCheji.Mafana.items.Items;
import me.TahaCheji.Mafana.items.Weapons;
import me.TahaCheji.Mafana.object.Title;
import me.TahaCheji.Mafana.stats.HP;
import net.minecraft.server.v1_16_R2.*;
import org.bukkit.*;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftDrowned;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftIronGolem;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import java.sql.SQLException;
import java.util.concurrent.ThreadLocalRandom;

public class FounderDrowned implements Listener {

    public FounderDrowned spawn(Location loc) {
        Drowned drowned = (Drowned) loc.getWorld().spawnEntity(loc, EntityType.DROWNED);

        EntityCreature c = (EntityCreature) ((CraftEntity) drowned).getHandle();

        drowned.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(7500);
        drowned.setHealth(7500);

        drowned.setCustomNameVisible(true);
        drowned.setCustomName(ChatColor.translateAlternateColorCodes
                ('&', "&7&l°*°FounderDrowned°*° " + ChatColor.RED + "♥" + ChatColor.RED + drowned.getHealth() + ChatColor.RED + "♥"));


        c.goalSelector.a(1, new PathfinderGoalNearestAttackableTarget<EntityHuman>(c, EntityHuman.class, true));
        c.goalSelector.a(1, new PathfinderGoalMeleeAttack(c, 4.0D, false));


        return (FounderDrowned) drowned;
    }
    

    @EventHandler
    public void FounderDrowned() {
        BukkitTask t = new BukkitRunnable() {
            @Override
            public void run() {
                org.bukkit.block.Block block1 = Bukkit.getServer().getWorld("world").getBlockAt(747, 67 , -560);


                ArmorStand as = (ArmorStand) block1.getWorld().spawnEntity(block1.getLocation(), EntityType.ARMOR_STAND);
                as.setVisible(false);
                as.setGravity(false);

                for (final Entity entity : as.getNearbyEntities(5, 5, 5)) {
                    if (entity.getCustomName().contains("FounderDrowned")) return;
                    new FounderDrowned().spawn(as.getLocation());
                }

                Drowned drowned = (Drowned) new FounderDrowned().spawn(block1.getLocation());
                WorldServer world1 = ((CraftWorld) block1.getLocation().getWorld()).getHandle();
                world1.addEntity((net.minecraft.server.v1_16_R2.Entity) drowned);




            }
        }.runTaskTimer(me.TahaCheji.Mafana.Main.getInstance(), 0L, 1200L);
    }

    @EventHandler
    public void Founderdrowned(EntityDamageByEntityEvent e) {
        if (e.getDamager() instanceof IronGolem && e.getEntity() instanceof Player) {
            Player player = (Player) e.getEntity();
            HP h = Main.getInstance().hpMap.get(player.getUniqueId());
            EntityDrowned mob = (EntityDrowned) e.getDamager();
            if (e.getEntity() instanceof FounderDrowned) {
                h.setHP(h.getHP() - 100);

                    player.setVelocity(new Vector(0, 25, 5));
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            player.spawnParticle(Particle.END_ROD, player.getLocation().clone().add(1,2,0), 5);
                        }
                    }.runTaskTimer((Plugin) this, 0, 10L);
                    player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_FALL, 10, 10);
                    Title title1 = new Title("Slam","Attack!",5,25,5);
                    title1.setTitleColor(ChatColor.DARK_RED);
                    title1.setSubtitleColor(ChatColor.RED);
                    title1.setTimingsToTicks();
                    title1.send(player);

            }
        }
    }

    //this dosnt work

    @EventHandler
    public void FoundersEvent(EntityDamageByEntityEvent e) {

        Entity entity = e.getEntity();

        if (e.getDamager() instanceof Player) {
                if (entity instanceof FounderDrowned) {

    //stage1


                    if(themobs.getHealth() >= 2000) {
    //stage2


                    }


                }


        }

    }
    
    //end of this dosnt work













    @EventHandler
    public void mobDeath(EntityDeathEvent e) throws SQLException {

        e.getDrops().clear();
        e.setDroppedExp(0);

        LivingEntity entity = e.getEntity();
        Player player = e.getEntity().getKiller();

        if (entity instanceof FounderDrowned) {
                int random = ThreadLocalRandom.current().nextInt(10);
                if (random < 1) {
                    player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_FALL, 10, 10);
                    player.sendMessage(ChatColor.DARK_AQUA + "Rare Drop: " + ChatColor.GREEN + "Bone Shard");
                    player.getInventory().addItem(Items.BoneShard());
                }
            }
        }

    }

Add a code snippet to your website: www.paste.org