package com.elmakers.mine.bukkit.spell.builtin;

import java.util.Collection;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;

import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.spell.UndoableSpell;
import com.elmakers.mine.bukkit.utility.CompatibilityUtils;
import com.elmakers.mine.bukkit.utility.Target;

public class PotionEffectSpell extends UndoableSpell
{
	@Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		Target target = getTarget();
		if (!target.hasEntity() || !(target.getEntity() instanceof LivingEntity))
		{
			return SpellResult.NO_TARGET;
		}
		LivingEntity targetEntity = (LivingEntity)target.getEntity();
		if (targetEntity != mage.getEntity()) {
			// Check for superprotected mages
			if (controller.isMage(targetEntity)) {
				Mage targetMage = controller.getMage(targetEntity);
				
				// Check for protected players
				if (targetMage.isSuperProtected()) {
					return SpellResult.NO_TARGET;
				}
				
				if (parameters.getBoolean("deactivate_target_mage")) {
					targetMage.deactivateAllSpells();
				}
			}
		}

        Integer duration = null;
        if (parameters.contains("duration")) {
            duration = parameters.getInt("duration");
        }
		Collection<PotionEffect> effects = getPotionEffects(parameters, duration);
		registerPotionEffects(targetEntity);
		CompatibilityUtils.applyPotionEffects(targetEntity, effects);
		registerForUndo();
		return SpellResult.CAST;
	}
}

@@ -59,26 +59,77 @@
 va.util.
-Collection
+ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List
 ;%0A%0Aimpor
@@ -173,24 +173,57 @@
 ionSection;%0A
+import org.bukkit.entity.Entity;%0A
 import org.b
@@ -754,17 +754,166 @@
 ;%0A%09%09if (
-!
+target.hasTarget())%0A%09%09%7B%0A%09%09%09return SpellResult.NO_TARGET;%0A%09%09%7D%0A%0A        List%3CLivingEntity%3E targetEntities = new ArrayList%3CLivingEntity%3E();%0A%0A        if (
 target.h
@@ -927,10 +927,10 @@
 y() 
-%7C%7C
+&&
  !(t
@@ -976,79 +976,774 @@
 ty))
-%0A%09%09%7B%0A%09%09%09return SpellResult.NO_TARGET;%0A%09%09%7D%0A%09%09LivingEntity targetEntity =
+ %7B%0A            targetEntities.add((LivingEntity)target.getEntity());%0A        %7D%0A%0A%0A        int radius = parameters.getInt(%22radius%22, 0);%0A        radius = (int)(mage.getRadiusMultiplier() * radius);%0A%0A        if (radius %3E 0) %7B%0A            List%3CEntity%3E entities = CompatibilityUtils.getNearbyEntities(location, radius, radius, radius);%0A            for (Entity entity : entities) %7B%0A                if (entity instanceof LivingEntity) %7B%0A                    targetEntities.add((LivingEntity)entity);%0A                %7D%0A            %7D%0A        %7D%0A%0A        Integer duration = null;%0A        if (parameters.contains(%22duration%22)) %7B%0A            duration = parameters.getInt(%22duration%22);%0A        %7D%0A%09%09Collection%3CPotionEffect%3E effects = getPotionEffects(parameters, duration);%0A        for
  (Li
@@ -1756,31 +1756,54 @@
 tity
-)
+ 
 target
-.getEntity();%0A%09%09
+Entity : targetEntities) %7B%0A            
 if (
@@ -1838,19 +1838,32 @@
 ty()) %7B%0A
-%09%09%09
+                
 // Check
@@ -1888,19 +1888,32 @@
 d mages%0A
-%09%09%09
+                
 if (cont
@@ -1943,20 +1943,36 @@
 ity)) %7B%0A
-%09%09%09%09
+                    
 Mage tar
@@ -2015,25 +2015,37 @@
 ntity);%0A
-%09%09%09%09%0A%09%09%09%09
+%0A                    
 // Check
@@ -2067,20 +2067,36 @@
 players%0A
-%09%09%09%09
+                    
 if (targ
@@ -2128,58 +2128,85 @@
 ) %7B%0A
-%09%09%09%09%09return SpellResult.NO_TARGET;%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09
+                        continue;%0A                    %7D%0A%0A                    
 if (
@@ -2260,13 +2260,32 @@
 ) %7B%0A
-%09%09%09%09%09
+                        
 targ
@@ -2318,247 +2318,75 @@
 ();%0A
-%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A        Integer duration = null;%0A        if (parameters.contains(%22duration%22)) %7B%0A            duration = parameters.getInt(%22duration%22);%0A        %7D%0A%09%09Collection%3CPotionEffect%3E effects = getPotionEffects(parameters, duration);%0A%09%09
+                    %7D%0A                %7D%0A            %7D%0A%0A            
 regi
@@ -2418,18 +2418,28 @@
 ntity);%0A
-%09%09
+            
 Compatib
@@ -2492,16 +2492,26 @@
 fects);%0A
+        %7D%0A
 %09%09regist

Add area of effect parameter to PotionEffectSpell