package squeek.veganoption.integration;

import java.util.HashMap;
import java.util.Map;
import cpw.mods.fml.common.Loader;

public class IntegrationHandler
{
	private static Map<String, IIntegrator> integrators = new HashMap<String, IIntegrator>();

	public static final String MODID_THERMAL_EXPANSION = "ThermalExpansion";
	public static final String MODID_HARVESTCRAFT = "HarvestCraft";
	public static final String MODID_MINEFACTORY_RELOADED = "MineFactoryReloaded";
	public static final String MODID_TINKERS_CONSTRUCT = "TConstruct";
	public static final String MODID_WITCHERY = "Witchery";
	public static final String MODID_WAILA = "Waila";
	public static final String MODID_VERSION_CHECKER = "VersionChecker";

	static
	{
		tryIntegration(MODID_THERMAL_EXPANSION, "cofh");
		tryIntegration(MODID_HARVESTCRAFT, "pams");
		tryIntegration(MODID_MINEFACTORY_RELOADED, "mfr");
		tryIntegration(MODID_TINKERS_CONSTRUCT, "tic");
		tryIntegration(MODID_WITCHERY, "witchery");
		tryIntegration(MODID_WAILA, "waila");
		tryIntegration(MODID_VERSION_CHECKER, "versionchecker");
	}

	public static void preInit()
	{
		for (IIntegrator integrator : integrators.values())
		{
			integrator.preInit();
		}
	}

	public static void init()
	{
		for (IIntegrator integrator : integrators.values())
		{
			integrator.init();
		}
	}

	public static void postInit()
	{
		for (IIntegrator integrator : integrators.values())
		{
			integrator.postInit();
		}
	}

	public static boolean tryIntegration(String modId, String packageName)
	{
		if (Loader.isModLoaded(modId))
		{
			try
			{
				String fullClassName = "squeek.veganoption.integration." + packageName + "." + modId;
				Class<?> clazz = IntegrationHandler.class.getClassLoader().loadClass(fullClassName);
				IIntegrator integrator = (IIntegrator) clazz.newInstance();
				integrators.put(modId, integrator);
				return true;
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		return false;
	}

	public static boolean modExists(String modId)
	{
		return integrators.containsKey(modId);
	}
}

@@ -372,16 +372,16 @@
  = %22
-H
+h
 arvest
-C
+c
 raft
@@ -815,16 +815,32 @@
 , %22pams%22
+, %22HarvestCraft%22
 );%0A%09%09try
@@ -1529,16 +1529,165 @@
 ame)%0A%09%7B%0A
+%09%09return tryIntegration(modId, packageName, modId);%0A%09%7D%0A%0A%09public static boolean tryIntegration(String modId, String packageName, String className)%0A%09%7B%0A
 %09%09if (Lo
@@ -1810,21 +1810,25 @@
 + %22.%22 + 
-modId
+className
 ;%0A%09%09%09%09Cl

Fix HarvestCraft modid/integration