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 BaseSpell spell;
    protected MageSpell mageSpell;
    protected UndoableSpell undoSpell;
    protected ActionSpell actionSpell;
    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 ActionHandler getActions(String key) {
        if (actionSpell != null)
        {
            return actionSpell.getActions(key);
        }
        return null;
    }

    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)
    {
        if (spell instanceof BaseSpell)
        {
            this.spell = (BaseSpell)spell;
        }
        if (spell instanceof MageSpell)
        {
            this.mageSpell = (MageSpell)spell;
        }
        if (spell instanceof UndoableSpell)
        {
            this.undoSpell = (UndoableSpell)spell;
        }
        if (spell instanceof ActionSpell)
        {
            this.actionSpell = (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;
    }
}

@@ -86,24 +86,81 @@
 pellAction;%0A
+import com.elmakers.mine.bukkit.api.effect.EffectPlayer;%0A
 import com.e
@@ -415,16 +415,75 @@
 nUtils;%0A
+import org.bukkit.Location;%0Aimport org.bukkit.block.Block;%0A
 import o
@@ -613,16 +613,116 @@
 .Entity;
+%0Aimport org.bukkit.potion.PotionEffect;%0Aimport org.bukkit.util.Vector;%0A%0Aimport java.util.Collection;
 %0A%0Apublic
@@ -784,23 +784,46 @@
 %7B%0A    pr
-otec
+ivate Spell spell;%0A    priva
 te
-d
  BaseSpe
@@ -821,25 +821,29 @@
 e BaseSpell 
-s
+baseS
 pell;%0A    pr
@@ -842,23 +842,56 @@
 ;%0A    pr
-otec
+ivate BlockSpell blockSpell;%0A    priva
 te
-d
  MageSpe
@@ -910,23 +910,21 @@
 ;%0A    pr
-otec
+iva
 te
-d
  Undoabl
@@ -947,23 +947,21 @@
 ;%0A    pr
-otec
+iva
 te
-d
  ActionS
@@ -988,15 +988,13 @@
   pr
-otec
+iva
 te
-d
  Con
@@ -1683,32 +1683,955 @@
 rn null;%0A    %7D%0A%0A
+    public Vector getDirection() %7B%0A        return baseSpell != null ? baseSpell.getDirection() : null;%0A    %7D%0A%0A    public Location getLocation() %7B%0A        return baseSpell != null ? baseSpell.getLocation() : null;%0A    %7D%0A%0A    public Location getEyeLocation() %7B%0A        return baseSpell != null ? baseSpell.getLocation() : null;%0A    %7D%0A%0A    public boolean isIndestructible(Block block) %7B%0A        return blockSpell != null ? blockSpell.isIndestructible(block) : true;%0A    %7D%0A%0A    public boolean hasBuildPermission(Block block) %7B%0A        return blockSpell != null ? blockSpell.hasBuildPermission(block) : false;%0A    %7D%0A%0A    public Collection%3CEffectPlayer%3E getEffects(String key) %7B%0A        return spell.getEffects(key);%0A    %7D%0A%0A    public Collection%3CPotionEffect%3E getPotionEffects(ConfigurationSection parameters, Integer duration) %7B%0A        return baseSpell != null ? baseSpell.getPotionEffects(parameters, duration) : null;%0A    %7D%0A%0A
     public Mage 
@@ -2936,32 +2936,60 @@
 rameters)%0A    %7B%0A
+        this.spell = spell;%0A
         if (spel
@@ -3035,25 +3035,29 @@
        this.
-s
+baseS
 pell = (Base
@@ -3406,32 +3406,142 @@
 pell;%0A        %7D%0A
+        if (spell instanceof BlockSpell)%0A        %7B%0A            this.blockSpell = (BlockSpell)spell;%0A        %7D%0A
         this.par

Add more BaseSpellAction passthrough methods, hide spell references.