package me.TehGoldyLockz.OlympicHeroes.listeners;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.SpectralArrow;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;

import me.TehGoldyLockz.OlympicHeroes.Cooldowns;
import me.TehGoldyLockz.OlympicHeroes.OlympicHeroes;
import me.TehGoldyLockz.OlympicHeroes.Variables;
import me.TehGoldyLockz.OlympicHeroes.player.OHPlayer;

public class PlayerListener implements Listener{

	OlympicHeroes plugin;
	
	public PlayerListener(OlympicHeroes plugin) {
		this.plugin = plugin;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
	}
	
	@EventHandler
	public void onDamage(EntityDamageEvent e) {
		if(e.getEntity() instanceof Player) {
			Player player = (Player) e.getEntity();
			OHPlayer ohPlayer = new OHPlayer(player);
			
			if(e.getCause() == DamageCause.FALL) {
				if(ohPlayer.getXP("Zeus") > 0) {
					e.setDamage(e.getFinalDamage() / 1.5);
					player.sendMessage("Your fall damage has been reduced thanks to Zeus");
				}
			}
		}
	}
	
	@EventHandler
	public void onBowShoot(EntityShootBowEvent e) {
		if(e.getEntity() instanceof Player) {
			Player player = (Player) e.getEntity();
			OHPlayer ohPlayer = new OHPlayer(player);

			if(ohPlayer.getLevel("Artemis") >= 3) {
				if(e.getBow().containsEnchantment(Enchantment.ARROW_INFINITE) == false && player.getGameMode() != GameMode.CREATIVE) {
					player.getInventory().addItem(new ItemStack(Material.ARROW, 1));
					player.getInventory().remove(new ItemStack(Material.ARROW, 1));
					
				}
			}
			
		}
	}
	
	@EventHandler
	public void onShootEntity(ProjectileHitEvent e) {
		if(e.getEntity().getShooter() instanceof Player) {
			Player player = (Player) e.getEntity().getShooter();
			OHPlayer ohPlayer = new OHPlayer(player);
			if(ohPlayer.getLevel("Apollo") >= 2) {
				if(e.getHitEntity() != null) {
					e.getHitEntity().setGlowing(true);
					
					Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

						@Override
						public void run() {
							if(e.getHitEntity().isDead() == false) {
								e.getHitEntity().setGlowing(false);
							}
						}
						
					}, 200L);
				}
			}
			
			if(ohPlayer.getLevel("Apollo") >= 3) {
				long time = player.getWorld().getTime();
				if(time <= 13500 || time >= 23000) {
					e.getHitEntity().setFireTicks(300);
				}
			}
		}
	}
	
	@EventHandler
	public void onInteract(PlayerInteractEvent e) {
		if(e.getAction() == Action.RIGHT_CLICK_AIR && e.getHand() == EquipmentSlot.HAND) {
			ItemStack item = e.getItem();
			
			if(item.getType() == Material.DIAMOND_SWORD || item.getType() == Material.GOLD_SWORD ||
			   item.getType() == Material.IRON_SWORD || item.getType() == Material.STONE_SWORD ||
			   item.getType() == Material.WOOD_SWORD) {
				OHPlayer ohPlayer = new OHPlayer(e.getPlayer());
				if(ohPlayer.getLevel("Zeus") >= 5) {
					
					if(!Cooldowns.lightningCooldown.contains(e.getPlayer())) {
						Block block = e.getPlayer().getTargetBlock(null, 100);
						Location l = block.getLocation();
						e.getPlayer().getWorld().strikeLightning(l);
						Cooldowns.lightningCooldown.add(e.getPlayer());
						OlympicHeroes.removeCooldown(plugin, Cooldowns.lightningCooldown, e.getPlayer(), Variables.LIGHTNING_COOLDOWN);
					}else {
						e.getPlayer().sendMessage("That ability is on cooldown.");
					}
				}
			}
		}
	}
	
}

@@ -225,24 +225,56 @@
 nchantment;%0A
+import org.bukkit.entity.Arrow;%0A
 import org.b
@@ -292,16 +292,20 @@
 y.Entity
+Type
 ;%0Aimport
@@ -323,22 +323,34 @@
 .entity.
-Player
+Arrow.PickupStatus
 ;%0Aimport
@@ -372,21 +372,14 @@
 ity.
-SpectralArrow
+Player
 ;%0Aim
@@ -2044,148 +2044,154 @@
 %09%09%09%09
-player.getInventory().addItem(new ItemStack(Material.ARROW, 1));%0A%09%09%09%09%09player.getInventory().remove(new ItemStack(Material
+((Arrow) e.getProjectile()).setPickupStatus(PickupStatus.DISALLOWED);%0A%09%09%09%09%09player.getWorld().spawnEntity(player.getLocation(), EntityType
 .ARROW
-, 1)
 );%0A
-%09%09%09%09%09%0A
 %09%09%09%09
@@ -2197,20 +2197,16 @@
 %09%7D%0A%09%09%09%7D%0A
-%09%09%09%0A
 %09%09%7D%0A%09%7D%0A%09

change artemis