package com.laytonsmith.abstraction.bukkit;

import org.bukkit.Material;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.laytonsmith.abstraction.MCColor;
import com.laytonsmith.abstraction.MCItemFactory;
import com.laytonsmith.abstraction.MCItemMeta;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.blocks.MCMaterial;

/**
 * 
 * @author jb_aero
 */
public class BukkitMCItemFactory implements MCItemFactory {

	ItemFactory f;
	public BukkitMCItemFactory(ItemFactory itemFactory) {
		this.f = itemFactory;
	}

	public MCItemMeta asMetaFor(MCItemMeta meta, MCItemStack stack) {
		ItemMeta bmeta = ((BukkitMCItemMeta) meta).asItemMeta();
		ItemStack bstack = ((BukkitMCItemStack) stack).asItemStack();
		return BukkitConvertor.BukkitGetCorrectMeta(f.asMetaFor(bmeta, bstack));
	}

	public MCItemMeta asMetaFor(MCItemMeta meta, MCMaterial material) {
		ItemMeta bmeta = ((BukkitMCItemMeta) meta).asItemMeta();
		Material bmat = Material.getMaterial(material.getType());
		return BukkitConvertor.BukkitGetCorrectMeta(f.asMetaFor(bmeta, bmat));
	}

	public boolean equals(MCItemMeta meta1, MCItemMeta meta2) {
		return f.equals(((BukkitMCItemMeta) meta1).asItemMeta(), ((BukkitMCItemMeta) meta2).asItemMeta());
	}

	public MCColor getDefaultLeatherColor() {
		return BukkitMCColor.GetMCColor(f.getDefaultLeatherColor());
	}

	public MCItemMeta getItemMeta(MCMaterial material) {
		ItemMeta im = f.getItemMeta(Material.getMaterial(material.getType()));
		return BukkitConvertor.BukkitGetCorrectMeta(im);
	}

	public boolean isApplicable(MCItemMeta meta, MCItemStack stack) {
		ItemMeta bmeta = ((BukkitMCItemMeta) meta).asItemMeta();
		ItemStack bstack = ((BukkitMCItemStack) stack).asItemStack();
		return f.isApplicable(bmeta, bstack);
	}

	public boolean isApplicable(MCItemMeta meta, MCMaterial material) {
		ItemMeta bmeta = ((BukkitMCItemMeta) meta).asItemMeta();
		Material bmat = Material.getMaterial(material.getType());
		return f.isApplicable(bmeta, bmat);
	}

}

@@ -1480,32 +1480,76 @@
 ial material) %7B%0A
+%09%09if(material == null)%7B%0A%09%09%09return null;%0A%09%09%7D%0A
 %09%09ItemMeta im = 

Return null, instead of throwing a NPE at this level.