package com.elmakers.mine.bukkit.spell;

import com.elmakers.mine.bukkit.api.action.SpellAction;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MageController;
import com.elmakers.mine.bukkit.api.spell.Spell;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.entity.Entity;

public abstract class BaseSpellAction implements SpellAction
{
    protected ActionSpell spell;
    protected ConfigurationSection parameters;

    public void registerModified(Entity entity)
    {
        spell.registerModified(entity);
    }

    public void registerForUndo(Entity entity) {
        spell.registerForUndo(entity);
    }

    public void registerPotionEffects(Entity entity)
    {
        spell.registerPotionEffects(entity);
    }

    public Mage getMage() {
        return spell.getMage();
    }

    public MageController getController() {
        return spell.getMage().getController();
    }

    @Override
    public void load(Spell spell, ConfigurationSection parameters)
    {
        if (spell instanceof ActionSpell)
        {
            this.spell = (ActionSpell)spell;
        }
        this.parameters = parameters;
    }

    @Override
    public ConfigurationSection getParameters(ConfigurationSection baseParameters)
    {
        if (parameters == null)
        {
            return baseParameters;
        }
        ConfigurationSection combined = new MemoryConfiguration();
        ConfigurationUtils.addConfigurations(combined, baseParameters);
        ConfigurationUtils.addConfigurations(combined, parameters);
        return combined;
    }

    @Override
    public boolean usesBrush()
    {
        return false;
    }

    @Override
    public boolean isUndoable()
    {
        return false;
    }
}

@@ -196,16 +196,69 @@
 roller;%0A
+import com.elmakers.mine.bukkit.api.spell.MageSpell;%0A
 import c
@@ -576,22 +576,16 @@
 otected 
-Action
 Spell sp
@@ -585,24 +585,98 @@
 pell spell;%0A
+    protected MageSpell mageSpell;%0A    protected UndoableSpell undoSpell;%0A
     protecte
@@ -765,33 +765,82 @@
 )%0A    %7B%0A        
-s
+if (undoSpell != null)%0A        %7B%0A            undoS
 pell.registerMod
@@ -846,32 +846,42 @@
 dified(entity);%0A
+        %7D%0A
     %7D%0A%0A    publi
@@ -917,16 +917,20 @@
  entity)
+%0A   
  %7B%0A     
@@ -924,33 +924,82 @@
 )%0A    %7B%0A        
-s
+if (undoSpell != null)%0A        %7B%0A            undoS
 pell.registerFor
@@ -1004,32 +1004,42 @@
 orUndo(entity);%0A
+        %7D%0A
     %7D%0A%0A    publi
@@ -1096,17 +1096,66 @@
         
-s
+if (undoSpell != null)%0A        %7B%0A            undoS
 pell.reg
@@ -1178,24 +1178,34 @@
 ts(entity);%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1224,16 +1224,20 @@
 etMage()
+%0A   
  %7B%0A     
@@ -1238,33 +1238,64 @@
 %0A        return 
-s
+mageSpell == null ? null : mageS
 pell.getMage();%0A
@@ -1357,30 +1357,72 @@
     
-return spell.getM
+Mage mage = getMage();%0A        return mage == null ? null : m
 age
-()
 .get
@@ -1541,35 +1541,172 @@
     
-if (spell instanceof Action
+this.spell = spell;%0A        if (spell instanceof MageSpell)%0A        %7B%0A            this.mageSpell = (MageSpell)spell;%0A        %7D%0A        if (spell instanceof Undoable
 Spel
@@ -1739,17 +1739,21 @@
 his.
-s
+undoS
 pell = (
 Acti
@@ -1748,22 +1748,24 @@
 pell = (
-Action
+Undoable
 Spell)sp

Fix non action spells using spell actions.