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

import com.elmakers.mine.bukkit.action.BaseSpellAction;
import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.batch.Batch;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MageController;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;

public class CancelAction extends BaseSpellAction
{
	private String undoListName;
    private String targetSpellKey;

    @Override
    public void prepare(CastContext context, ConfigurationSection parameters)
    {
        super.prepare(context, parameters);
        targetSpellKey = parameters.getString("spell", null);
    }

    @Override
	public SpellResult perform(CastContext context)
	{
		Entity targetEntity = context.getTargetEntity();
        MageController controller = context.getController();
		if (targetEntity == null || !controller.isMage(targetEntity)) {
            return SpellResult.NO_TARGET;
        }

        Mage targetMage = controller.getMage(targetEntity);
        Batch batch = (targetSpellKey == null || targetSpellKey.isEmpty())
                ? targetMage.cancelPending(true)
                : targetMage.cancelPending(targetSpellKey);
        if (batch == null) {
            return SpellResult.NO_TARGET;
        }
        undoListName = batch.getName();

        return SpellResult.CAST;
	}

    @Override
    public boolean requiresTargetEntity() {
        return true;
    }

    @Override
    public String transformMessage(String message) {
		return message.replace("$spell", undoListName == null ? "Unknown" : undoListName);
	}
}

@@ -365,16 +365,76 @@
 Result;%0A
+import com.elmakers.mine.bukkit.utility.ConfigurationUtils;%0A
 import o
@@ -513,16 +513,74 @@
 ntity;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Collection;%0A%0A
 public c
@@ -669,29 +669,36 @@
 ate 
-String targetS
+Collection%3CString%3E s
 pellKey
+s
 ;%0A%0A 
@@ -850,61 +850,443 @@
     
-targetSpellKey = parameters.getString(%22spell%22, null);
+if (parameters.contains(%22spells%22)) %7B%0A            spellKeys = ConfigurationUtils.getStringList(parameters, %22spells%22);%0A        %7D else if (parameters.contains(%22spell%22)) %7B%0A            String targetSpellKey = parameters.getString(%22spell%22, null);%0A            if (targetSpellKey != null && !targetSpellKey.isEmpty()) %7B%0A                spellKeys = new ArrayList%3CString%3E();%0A                spellKeys.add(targetSpellKey);%0A            %7D%0A        %7D
 %0A   
@@ -1582,24 +1582,76 @@
 %0A        %7D%0A%0A
+        SpellResult result = SpellResult.NO_TARGET;%0A
         Mage
@@ -1694,24 +1694,61 @@
 getEntity);%0A
+        if (spellKeys == null) %7B%0A    
         Batc
@@ -1761,109 +1761,242 @@
 h = 
-(
 target
-SpellKey == null %7C%7C targetSpellKey.isEmpty())%0A                ? targetMage.cancelPending(true)
+Mage.cancelPending(true);%0A            if (batch != null) %7B%0A                result = SpellResult.CAST;%0A                undoListName = batch.getName();%0A            %7D%0A        %7D else %7B%0A            for (String spellKey : spellKeys) %7B
 %0A   
@@ -2008,17 +2008,29 @@
         
-:
+Batch batch =
  targetM
@@ -2047,23 +2047,17 @@
 Pending(
-targetS
+s
 pellKey)
@@ -2058,32 +2058,40 @@
 llKey);%0A        
+   
+     
 if (batch == nul
@@ -2084,17 +2084,17 @@
  (batch 
-=
+!
 = null) 
@@ -2099,38 +2099,48 @@
 ) %7B%0A            
+     
-return
+   result =
  SpellResult.NO_
@@ -2132,32 +2132,27 @@
 SpellResult.
-NO_TARGE
+CAS
 T;%0A        %7D
@@ -2142,34 +2142,36 @@
 t.CAST;%0A        
-%7D%0A
+    
         undoList
@@ -2198,40 +2198,71 @@
 ();%0A
-%0A        return SpellResult.CAST
+                %7D%0A            %7D%0A        %7D%0A        return result
 ;%0A%09%7D
@@ -2443,21 +2443,20 @@
 place(%22$
-spell
+undo
 %22, undoL

Add "spells" parameter to Cancel action