package com.censoredsoftware.demigods.util;

import com.censoredsoftware.demigods.Demigods;
import com.censoredsoftware.demigods.structure.Structure;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Location;
import org.bukkit.entity.Player;

public class Zones
{
	/**
	 * Returns true if <code>location</code> is within a no-PVP zone.
	 * 
	 * @param location the location to check.
	 * @return true/false depending on if it's a no-PVP zone or not.
	 */
	public static boolean zoneNoPVP(Location location)
	{
		if(Demigods.config.getSettingBoolean("zones.allow_skills_anywhere")) return false;
		if(Demigods.worldguard != null) return Structures.isInRadiusWithFlag(location, Structure.Flag.NO_PVP) || !canWorldGuardDynamicPVP(location);
		return Structures.isInRadiusWithFlag(location, Structure.Flag.NO_PVP);
	}

	private static boolean canWorldGuardDynamicPVP(Location location)
	{
		for(ProtectedRegion region : Demigods.worldguard.getRegionManager(location.getWorld()).getApplicableRegions(location))
			if(region.getId().toLowerCase().contains("nopvp")) return false;
		return true;
	}

	/**
	 * Returns true if <code>location</code> is within a no-build zone
	 * for <code>player</code>.
	 * 
	 * @param player the player to check.
	 * @param location the location to check.
	 * @return true/false depending on the position of the <code>player</code>.
	 */
	public static boolean zoneNoBuild(Player player, Location location)
	{
		return !Demigods.worldguard.canBuild(player, location);
	}
}

@@ -143,16 +143,101 @@
 ucture;%0A
+import com.google.common.base.Predicate;%0Aimport com.google.common.collect.Iterators;%0A
 import c
@@ -1002,37 +1002,30 @@
 %7B%0A%09%09
-for(ProtectedRegion region : 
+return !Iterators.any(
 Demi
@@ -1112,16 +1112,135 @@
 ion)
-)%0A%09%09%09if(
+.iterator(), new Predicate%3CProtectedRegion%3E()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public boolean apply(ProtectedRegion region)%0A%09%09%09%7B%0A%09%09%09%09return 
 regi
@@ -1285,37 +1285,19 @@
 vp%22)
-) return false;%0A%09%09return true
+;%0A%09%09%09%7D%0A%09%09%7D)
 ;%0A%09%7D

Make this faster.