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

import java.util.Set;

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

import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.block.BoundingBox;
import com.elmakers.mine.bukkit.spell.BlockSpell;

public class PortalSpell extends BlockSpell
{
	@Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		Block target = getTargetBlock();
		if (target == null)
		{
			return SpellResult.NO_TARGET;
		}
		if (!hasBuildPermission(target)) 
		{
			return SpellResult.INSUFFICIENT_PERMISSION;
		}

		Material blockType = target.getType();
		Block portalBase = target.getRelative(BlockFace.UP);
		blockType = portalBase.getType();
		if (blockType != Material.AIR)
		{
			portalBase = getPreviousBlock();
		}

		blockType = portalBase.getType();
		if (blockType != Material.AIR && blockType != Material.SNOW)
		{
			return SpellResult.NO_TARGET;		
		}

		controller.disablePhysics(1000);
		buildPortalBlocks(portalBase.getLocation(), BlockFace.NORTH);
		registerForUndo();

		return SpellResult.CAST;
	}

	protected void buildPortalBlocks(Location centerBlock, BlockFace facing)
	{
		Set<Material> destructible = mage.getController().getDestructibleMaterials();
		BoundingBox container = new BoundingBox(centerBlock.getBlockX(), centerBlock.getBlockY(), centerBlock.getBlockZ(), centerBlock.getBlockX() + 2, centerBlock.getBlockY() + 3, centerBlock.getBlockZ() + 1);
		container.fill(centerBlock.getWorld(), Material.PORTAL, destructible, getUndoList());
	}
}

@@ -806,16 +806,110 @@
 ce.UP);%0A
+        if (portalBase == null)%0A        %7B%0A            return SpellResult.NO_TARGET;%0A        %7D%0A
 %09%09blockT
@@ -1008,24 +1008,118 @@
 Block();%0A%09%09%7D
+%0A        if (portalBase == null)%0A        %7B%0A            return SpellResult.NO_TARGET;%0A        %7D
 %0A%0A%09%09blockTyp

Add some null checks to PortalSpell to try and catch an NPE reported by SmallSansSerif