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;
|
2014-04-16 04:46:22 -04:00
|
|
|
import tconstruct.plugins.fmp.ForgeMultiPart;
|
2013-12-01 23:17:22 +00:00
|
|
|
import tconstruct.plugins.ic2.IC2;
|
2013-12-19 10:10:10 -05:00
|
|
|
import tconstruct.plugins.imc.AppEng;
|
2014-02-15 12:56:25 -05:00
|
|
|
import tconstruct.plugins.imc.BuildcraftTransport;
|
2013-12-19 10:10:10 -05:00
|
|
|
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;
|
2013-11-29 19:46:40 +00:00
|
|
|
private Configuration conf = null;
|
2013-11-29 20:33:49 +00:00
|
|
|
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()
|
|
|
|
|
{
|
2013-11-29 19:46:40 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 19:46:40 +00:00
|
|
|
/**
|
|
|
|
|
* Register a plugin with the controller.
|
2014-02-16 14:23:50 -05:00
|
|
|
*
|
|
|
|
|
* 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-29 19:46:40 +00:00
|
|
|
*/
|
2014-02-05 09:11:06 -05:00
|
|
|
public void registerPlugin (ICompatPlugin plugin)
|
2013-11-16 16:34:38 +00:00
|
|
|
{
|
2013-11-29 20:33:49 +00:00
|
|
|
conf.load();
|
|
|
|
|
boolean shouldLoad = conf.get("Plugins", plugin.getModId(), true).getBoolean(true);
|
|
|
|
|
conf.save();
|
2013-11-29 19:46:40 +00:00
|
|
|
|
2013-11-29 21:10:58 +00:00
|
|
|
if (shouldLoad)
|
|
|
|
|
loadPlugin(plugin);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// 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)
|
2013-11-29 21:10:58 +00:00
|
|
|
{
|
2014-02-05 09:11:06 -05:00
|
|
|
if (!Loader.isModLoaded(plugin.getModId()))
|
|
|
|
|
return;
|
2013-11-29 21:10:58 +00:00
|
|
|
|
|
|
|
|
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
|
2013-11-29 20:33:49 +00:00
|
|
|
{
|
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
|
|
|
{
|
2013-11-29 21:10:58 +00:00
|
|
|
// Mystcraft is pushed in through the backdoor so it can't be disabled.
|
|
|
|
|
loadPlugin(new Mystcraft());
|
|
|
|
|
|
2013-11-29 20:33:49 +00:00
|
|
|
registerPlugin(new AppEng());
|
2014-02-15 12:56:25 -05:00
|
|
|
registerPlugin(new BuildcraftTransport());
|
2014-04-16 04:46:22 -04: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());
|
2014-02-16 14:23:50 -05:00
|
|
|
// registerPlugin(new NotEnoughItems());
|
2013-11-29 20:33:49 +00:00
|
|
|
registerPlugin(new Thaumcraft());
|
2014-02-05 09:11:06 -05:00
|
|
|
// registerPlugin(new Waila());
|
2013-11-16 16:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|