package com.censoredsoftware.demigods.episodes.demo.ability.passive;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;

import com.censoredsoftware.demigods.engine.data.DataManager;
import com.censoredsoftware.demigods.engine.element.Ability;
import com.censoredsoftware.demigods.engine.element.Deity;

public class Swim extends Ability
{
	private final static String name = "Swim", command = null;
	private final static int cost = 0, delay = 0, repeat = 20;
	private static Info info;
	private final static Devotion.Type type = Devotion.Type.PASSIVE;
	private final static List<String> details = new ArrayList<String>(1)
	{
		{
			add("Crouch while in water to swim very fast.");
		}
	};

	public Swim(final String deity, String permission)
	{
		super(info = new Info(deity, name, command, permission, cost, delay, repeat, details, type), new Listener()
		{
			@EventHandler(priority = EventPriority.HIGHEST)
			private void onPlayerMoveEvent(PlayerMoveEvent event)
			{
				Player player = event.getPlayer();

				if(!(player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER) || player.getLocation().getBlock().getType().equals(Material.WATER) || player.isSneaking()))
				{
					DataManager.removeTemp(player.getName(), "is_swimming");
					return;
				}
				else if(player.isSneaking() && DataManager.hasKeyTemp(player.getName(), "is_swimming"))
				{
					Vector direction = player.getLocation().getDirection().normalize().multiply(1.3D);
					Vector victor = new Vector(direction.getX(), direction.getY(), direction.getZ());
					player.setVelocity(victor);
					return;
				}
				else if(player.isSneaking() && (player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER) || player.getLocation().getBlock().getType().equals(Material.WATER)) && Deity.Util.canUseDeitySilent(player, deity))
				{
					DataManager.saveTemp(player.getName(), "is_swimming", true);
					return;
				}
			}
		}, null);
	}
}

@@ -1267,17 +1267,40 @@
 %09%09%09%09if(!
-(
+player.isSneaking() %7C%7C !
 player.g
@@ -1362,32 +1362,33 @@
 ONARY_WATER) %7C%7C 
+!
 player.getLocati
@@ -1439,32 +1439,8 @@
 TER)
- %7C%7C player.isSneaking())
 )%0A%09%09
@@ -1614,16 +1614,165 @@
 imming%22)
+ && (player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER) %7C%7C player.getLocation().getBlock().getType().equals(Material.WATER))
 )%0A%09%09%09%09%7B%0A

Fix for swimming ability flying exploit.