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

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

import com.elmakers.mine.bukkit.api.block.MaterialBrush;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.spell.BrushSpell;
import com.elmakers.mine.bukkit.utility.Target;

public class PlaceSpell extends BrushSpell 
{
	@Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		Target attachToBlock = getTarget();
		if (!attachToBlock.isValid()) return SpellResult.NO_TARGET;
		Block placeBlock = getPreviousBlock();

		if (!hasBuildPermission(placeBlock)) {
			return SpellResult.INSUFFICIENT_PERMISSION;
		}


        MaterialBrush buildWith = getBrush();
        buildWith.setTarget(attachToBlock.getLocation(), placeBlock.getLocation());
        buildWith.update(mage, placeBlock.getLocation());

		registerForUndo(placeBlock);
		buildWith.modify(placeBlock);

		registerForUndo();

		return SpellResult.CAST;
	}
}

@@ -602,16 +602,79 @@
 ock();%0A%0A
+        if (placeBlock == null) return SpellResult.NO_TARGET;%0A%0A
 %09%09if (!h

Fix NPE in PlaceSpell on invalid target