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

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;

import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.block.batch.BlockRecurse;
import com.elmakers.mine.bukkit.block.batch.ReplaceMaterialAction;
import com.elmakers.mine.bukkit.spell.BrushSpell;

public class RecurseSpell extends BrushSpell 
{
	private final BlockRecurse blockRecurse = new BlockRecurse();

	@Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		Block targetBlock = getTargetBlock();
		
		if (targetBlock == null) 
		{
			return SpellResult.NO_TARGET;
		}
		if (!hasBuildPermission(targetBlock)) 
		{
			return SpellResult.INSUFFICIENT_PERMISSION;
		}
		
		int size = parameters.getInt("size", 8);
		size = (int)(mage.getRadiusMultiplier() * size);
		blockRecurse.setMaxRecursion(size);

		Material targetMaterial = targetBlock.getType();
		ReplaceMaterialAction action = new ReplaceMaterialAction(this, targetBlock);

		// A bit hacky, but is very handy!
		if (targetMaterial == Material.STATIONARY_WATER || targetMaterial == Material.WATER)
		{
			for (byte i = 0; i < 9; i++) {
				action.addReplaceable(Material.STATIONARY_WATER, i);
				action.addReplaceable(Material.WATER, i);
			}
		}
		else if (targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA)
		{
			for (byte i = 0; i < 9; i++) {
				action.addReplaceable(Material.STATIONARY_LAVA, i);
				action.addReplaceable(Material.LAVA, i);
			}
		}
		else if (targetMaterial == Material.SNOW) {
			for (byte i = 0; i < 8; i++) {
				action.addReplaceable(Material.SNOW, i);
			}
		}
		blockRecurse.recurse(targetBlock, action);
		mage.registerForUndo(action.getBlocks());
		controller.updateBlock(targetBlock);
		
		return SpellResult.CAST;
	}
}

@@ -781,16 +781,121 @@
 ION;%0A%09%09%7D
+%0A%0A        if (!isDestructible(targetBlock))%0A        %7B%0A            return SpellResult.NO_TARGET;%0A        %7D
 %0A%09%09%0A%09%09in
@@ -1027,59 +1027,8 @@
 );%0A%0A
-%09%09Material targetMaterial = targetBlock.getType();%0A
 %09%09Re
@@ -1101,16 +1101,73 @@
 tBlock);
+%0A        Material targetMaterial = targetBlock.getType();
 %0A%0A%09%09// A

Fix destructible check in RecurseSpell