Files
TinkersConstruct/src/main/java/tconstruct/plugins/PluginController.java
T

128 lines
3.5 KiB
Java
Raw Normal View History

2013-11-16 16:34:38 +00:00
package tconstruct.plugins;
2014-02-05 10:28:54 -05:00
import java.io.File;
import java.util.LinkedList;
import java.util.List;
2013-12-31 16:37:46 -05:00
import net.minecraftforge.common.config.Configuration;
2013-11-16 16:34:38 +00:00
import tconstruct.TConstruct;
2013-12-01 23:17:22 +00:00
import tconstruct.plugins.ic2.IC2;
import tconstruct.plugins.imc.AppEng;
2014-02-15 12:56:25 -05:00
import tconstruct.plugins.imc.BuildcraftTransport;
import tconstruct.plugins.imc.Mystcraft;
import tconstruct.plugins.imc.Thaumcraft;
2014-02-05 10:28:54 -05:00
import cpw.mods.fml.common.Loader;
2013-11-16 16:34:38 +00:00
public class PluginController
{
2014-02-05 09:11:06 -05:00
private enum Phase
{
2013-11-16 16:34:38 +00:00
PRELAUNCH, PREINIT, INIT, POSTINIT, DONE
}
private static PluginController instance;
private Configuration conf = null;
private List<ICompatPlugin> plugins = new LinkedList<ICompatPlugin>();
2013-11-16 16:34:38 +00:00
private Phase currPhase = Phase.PRELAUNCH;
2014-02-05 09:11:06 -05: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
2014-02-05 09:11:06 -05:00
public static PluginController getController ()
2013-11-16 16:34:38 +00:00
{
2014-02-05 09:11:06 -05:00
if (instance == null)
instance = new PluginController();
2013-11-16 16:34:38 +00:00
return instance;
}
/**
* 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
*/
2014-02-05 09:11:06 -05:00
public void registerPlugin (ICompatPlugin plugin)
2013-11-16 16:34:38 +00:00
{
conf.load();
boolean shouldLoad = conf.get("Plugins", plugin.getModId(), true).getBoolean(true);
conf.save();
if (shouldLoad)
loadPlugin(plugin);
}
// This does the actual plugin loading if mod is present; needed to allow force-enabling.
2014-02-05 09:11:06 -05:00
private void loadPlugin (ICompatPlugin plugin)
{
2014-02-05 09:11:06 -05:00
if (!Loader.isModLoaded(plugin.getModId()))
return;
TConstruct.logger.info("[PluginController] Registering compat plugin for " + plugin.getModId());
plugins.add(plugin);
2014-02-05 09:11:06 -05:00
switch (currPhase)
// Play catch-up if plugin is registered late
{
2014-02-05 09:11:06 -05:00
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;
2013-11-16 16:34:38 +00:00
}
}
2014-02-05 09:11:06 -05:00
public void preInit ()
2013-11-16 16:34:38 +00:00
{
currPhase = Phase.PREINIT;
2014-02-05 09:11:06 -05:00
for (ICompatPlugin pl : plugins)
pl.preInit();
2013-11-16 16:34:38 +00:00
}
2014-02-05 09:11:06 -05:00
public void init ()
2013-11-16 16:34:38 +00:00
{
currPhase = Phase.INIT;
2014-02-05 09:11:06 -05:00
for (ICompatPlugin pl : plugins)
pl.init();
2013-11-16 16:34:38 +00:00
}
2014-02-05 09:11:06 -05:00
public void postInit ()
2013-11-16 16:34:38 +00:00
{
currPhase = Phase.POSTINIT;
2014-02-05 09:11:06 -05:00
for (ICompatPlugin pl : plugins)
pl.postInit();
2013-11-16 16:34:38 +00:00
currPhase = Phase.DONE;
}
2014-02-05 09:11:06 -05:00
public void registerBuiltins ()
2013-11-16 16:34:38 +00:00
{
// Mystcraft is pushed in through the backdoor so it can't be disabled.
loadPlugin(new Mystcraft());
registerPlugin(new AppEng());
2014-02-15 12:56:25 -05:00
registerPlugin(new BuildcraftTransport());
2013-12-31 11:26:08 -05:00
//registerPlugin(new ForgeMultiPart());
2013-12-01 23:17:22 +00:00
registerPlugin(new IC2());
2014-02-05 09:11:06 -05:00
// registerPlugin(new MineFactoryReloaded());
2013-12-31 11:26:08 -05:00
//registerPlugin(new NotEnoughItems());
registerPlugin(new Thaumcraft());
2014-02-05 09:11:06 -05:00
// registerPlugin(new Waila());
2013-11-16 16:34:38 +00:00
}
}