mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-13 00:47:32 +00:00
TDynstruct.cfg can now be used to toggle compat plugins.
This commit is contained in:
1 parent
bd213f60d9
commit
4698b28179
2 files changed
+50
-7
No files matched your search
@@ -1,14 +1,18 @@
|
||||
package tconstruct.plugins;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.plugins.fmp.ForgeMultiPart;
|
||||
import tconstruct.plugins.minefactoryreloaded.MineFactoryReloaded;
|
||||
import tconstruct.plugins.nei.NotEnoughItems;
|
||||
import tconstruct.plugins.waila.Waila;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PluginController
|
||||
{
|
||||
@@ -18,10 +22,15 @@ public class PluginController
|
||||
}
|
||||
|
||||
private static PluginController instance;
|
||||
private List<ICompatPlugin> plugins = new ArrayList<ICompatPlugin>();
|
||||
private Configuration conf = null;
|
||||
private Map<ICompatPlugin, Boolean> plugins = new HashMap<ICompatPlugin, Boolean>();
|
||||
private Phase currPhase = Phase.PRELAUNCH;
|
||||
|
||||
private PluginController() {}
|
||||
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));
|
||||
}
|
||||
|
||||
public static PluginController getController()
|
||||
{
|
||||
@@ -29,12 +38,31 @@ public class PluginController
|
||||
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
|
||||
*/
|
||||
public void registerPlugin(ICompatPlugin plugin)
|
||||
{
|
||||
if (Loader.isModLoaded(plugin.getModId()))
|
||||
{
|
||||
TConstruct.logger.info("Registering compat plugin for " + plugin.getModId());
|
||||
plugins.add(plugin);
|
||||
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;
|
||||
}
|
||||
|
||||
switch (currPhase) // Play catch-up if plugin is registered late
|
||||
{
|
||||
@@ -60,19 +88,28 @@ public class PluginController
|
||||
public void preInit()
|
||||
{
|
||||
currPhase = Phase.PREINIT;
|
||||
for (ICompatPlugin plugin : plugins) plugin.preInit();
|
||||
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
||||
if (entry.getValue())
|
||||
entry.getKey().preInit();
|
||||
}
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
currPhase = Phase.INIT;
|
||||
for (ICompatPlugin plugin : plugins) plugin.init();
|
||||
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
||||
if (entry.getValue())
|
||||
entry.getKey().init();
|
||||
}
|
||||
}
|
||||
|
||||
public void postInit()
|
||||
{
|
||||
currPhase = Phase.POSTINIT;
|
||||
for (ICompatPlugin plugin : plugins) plugin.postInit();
|
||||
for (Map.Entry<ICompatPlugin, Boolean> entry : plugins.entrySet()){
|
||||
if (entry.getValue())
|
||||
entry.getKey().postInit();
|
||||
}
|
||||
currPhase = Phase.DONE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user