2013-11-16 16:34:38 +00:00
|
|
|
package tconstruct.plugins;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.Loader;
|
2013-11-29 19:46:40 +00:00
|
|
|
import net.minecraftforge.common.Configuration;
|
2013-11-16 16:34:38 +00:00
|
|
|
import tconstruct.TConstruct;
|
|
|
|
|
import tconstruct.plugins.fmp.ForgeMultiPart;
|
|
|
|
|
import tconstruct.plugins.minefactoryreloaded.MineFactoryReloaded;
|
|
|
|
|
import tconstruct.plugins.nei.NotEnoughItems;
|
|
|
|
|
import tconstruct.plugins.waila.Waila;
|
|
|
|
|
|
2013-11-29 19:46:40 +00:00
|
|
|
import java.io.File;
|
2013-11-16 16:34:38 +00:00
|
|
|
import java.util.ArrayList;
|
2013-11-29 19:46:40 +00:00
|
|
|
import java.util.HashMap;
|
2013-11-16 16:34:38 +00:00
|
|
|
import java.util.List;
|
2013-11-29 19:46:40 +00:00
|
|
|
import java.util.Map;
|
2013-11-16 16:34:38 +00:00
|
|
|
|
|
|
|
|
public class PluginController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private enum Phase {
|
|
|
|
|
PRELAUNCH, PREINIT, INIT, POSTINIT, DONE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static PluginController instance;
|
2013-11-29 19:46:40 +00:00
|
|
|
private Configuration conf = null;
|
|
|
|
|
private Map<ICompatPlugin, Boolean> plugins = new HashMap<ICompatPlugin, Boolean>();
|
2013-11-16 16:34:38 +00:00
|
|
|
private Phase currPhase = Phase.PRELAUNCH;
|
|
|
|
|
|
2013-11-29 19:46:40 +00:00
|
|
|
private PluginController() {
|
|
|
|
|
String path = Loader.instance().getConfigDir().toString() + File.separator + "TDynstruct.cfg";
|
|
|
|
|
TConstruct.logger.info("[PluginController] Using config path: " + path);
|
|
|
|
|
conf = new Configuration(new File(path));
|
|
|
|
|
}
|
2013-11-16 16:34:38 +00:00
|
|
|
|
|
|
|
|
public static PluginController getController()
|
|
|
|
|
{
|
|
|
|
|
if (instance == null) instance = new PluginController();
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 19:46:40 +00:00
|
|
|
/**
|
|
|
|
|
* Register a plugin with the controller.
|
|
|
|
|
*
|
|
|
|
|
* Warning: Make sure your plugin class imports no APIs directly! Any API interaction should be done by handlers called in pre/init/post so
|
|
|
|
|
* merely creating an instance to check the mod ID isn't a hazard to the controller.
|
|
|
|
|
*
|
|
|
|
|
* @param plugin Plugin to register
|
|
|
|
|
*/
|
2013-11-16 16:34:38 +00:00
|
|
|
public void registerPlugin(ICompatPlugin plugin)
|
|
|
|
|
{
|
|
|
|
|
if (Loader.isModLoaded(plugin.getModId()))
|
|
|
|
|
{
|
2013-11-29 19:46:40 +00:00
|
|
|
TConstruct.logger.info("[PluginController] Attempting registration of compat plugin for " + plugin.getModId());
|
|
|
|
|
plugins.put(plugin, true);
|
|
|
|
|
|
|
|
|
|
conf.load();
|
|
|
|
|
boolean shouldLoad = conf.get("Plugins", plugin.getModId(), true).getBoolean(true);
|
|
|
|
|
plugins.put(plugin, shouldLoad);
|
|
|
|
|
conf.save();
|
|
|
|
|
|
|
|
|
|
if (!shouldLoad)
|
|
|
|
|
{
|
|
|
|
|
TConstruct.logger.info("[PluginController] Aborting registration of compat plugin for " + plugin.getModId() + "; disabled in configuration.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-11-16 16:34:38 +00:00
|
|
|
|
|
|
|
|
switch (currPhase) // Play catch-up if plugin is registered late
|
|
|
|
|
{
|
|
|
|
|
case DONE:
|
|
|
|
|
case POSTINIT:
|
|
|
|
|
plugin.preInit();
|
|
|
|
|
plugin.init();
|
|
|
|
|
plugin.postInit();
|
|
|
|
|
break;
|
|
|
|
|
case INIT:
|
|
|
|
|
plugin.preInit();
|
|
|
|
|
plugin.init();
|
|
|
|
|
break;
|
|
|
|
|
case PREINIT:
|
|
|
|
|
plugin.preInit();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void preInit()
|
|
|
|
|
{
|
|
|
|
|
currPhase = Phase.PREINIT;
|
2013-11-29 19:46:40 +00:00
|
|
|
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
|
|
|
|
if (entry.getValue())
|
|
|
|
|
entry.getKey().preInit();
|
|
|
|
|
}
|
2013-11-16 16:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init()
|
|
|
|
|
{
|
|
|
|
|
currPhase = Phase.INIT;
|
2013-11-29 19:46:40 +00:00
|
|
|
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
|
|
|
|
if (entry.getValue())
|
|
|
|
|
entry.getKey().init();
|
|
|
|
|
}
|
2013-11-16 16:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void postInit()
|
|
|
|
|
{
|
|
|
|
|
currPhase = Phase.POSTINIT;
|
2013-11-29 19:46:40 +00:00
|
|
|
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
|
|
|
|
if (entry.getValue())
|
|
|
|
|
entry.getKey().postInit();
|
|
|
|
|
}
|
2013-11-16 16:34:38 +00:00
|
|
|
currPhase = Phase.DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registerBuiltins()
|
|
|
|
|
{
|
|
|
|
|
registerPlugin(new ForgeMultiPart());
|
|
|
|
|
registerPlugin(new MineFactoryReloaded());
|
|
|
|
|
registerPlugin(new NotEnoughItems());
|
|
|
|
|
registerPlugin(new Waila());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|