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.MageSpell;
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 Spell spell;
    protected MageSpell mageSpell;
    protected UndoableSpell undoSpell;
    protected ConfigurationSection parameters;

    public void registerModified(Entity entity)
    {
        if (undoSpell != null)
        {
            undoSpell.registerModified(entity);
        }
    }

    public void registerForUndo(Entity entity)
    {
        if (undoSpell != null)
        {
            undoSpell.registerForUndo(entity);
        }
    }

    public void registerPotionEffects(Entity entity)
    {
        if (undoSpell != null)
        {
            undoSpell.registerPotionEffects(entity);
        }
    }

    public Mage getMage()
    {
        return mageSpell == null ? null : mageSpell.getMage();
    }

    public MageController getController() {
        Mage mage = getMage();
        return mage == null ? null : mage.getController();
    }

    @Override
    public void load(Spell spell, ConfigurationSection parameters)
    {
        this.spell = spell;
        if (spell instanceof MageSpell)
        {
            this.mageSpell = (MageSpell)spell;
        }
        if (spell instanceof UndoableSpell)
        {
            this.undoSpell = (UndoableSpell)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;
    }
}

@@ -576,16 +576,20 @@
 otected 
+Base
 Spell sp
@@ -589,24 +589,24 @@
 pell spell;%0A
-
     protecte
@@ -663,24 +663,63 @@
  undoSpell;%0A
+    protected ActionSpell actionSpell;%0A
     protecte
@@ -1234,32 +1234,211 @@
        %7D%0A    %7D%0A%0A
+    public ActionHandler getActions(String key) %7B%0A        if (actionSpell != null)%0A        %7B%0A            return actionSpell.getActions(key);%0A        %7D%0A        return null;%0A    %7D%0A%0A
     public Mage 
@@ -1763,27 +1763,102 @@
     
-this.spell = spell;
+if (spell instanceof BaseSpell)%0A        %7B%0A            this.spell = (BaseSpell)spell;%0A        %7D
 %0A   
@@ -2007,32 +2007,32 @@
 pell)%0A        %7B%0A
-
             this
@@ -2068,32 +2068,145 @@
 pell;%0A        %7D%0A
+        if (spell instanceof ActionSpell)%0A        %7B%0A            this.actionSpell = (ActionSpell)spell;%0A        %7D%0A
         this.par

Fix calling base spell methods from an action