-
Notifications
You must be signed in to change notification settings - Fork 755
/
PluginController.java
87 lines (73 loc) · 2.27 KB
/
PluginController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package tconstruct.plugins;
import cpw.mods.fml.common.Loader;
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.util.ArrayList;
import java.util.List;
public class PluginController
{
private enum Phase {
PRELAUNCH, PREINIT, INIT, POSTINIT, DONE
}
private static PluginController instance;
private List<ICompatPlugin> plugins = new ArrayList<ICompatPlugin>();
private Phase currPhase = Phase.PRELAUNCH;
private PluginController() {}
public static PluginController getController()
{
if (instance == null) instance = new PluginController();
return instance;
}
public void registerPlugin(ICompatPlugin plugin)
{
if (Loader.isModLoaded(plugin.getModId()))
{
TConstruct.logger.info("Registering compat plugin for " + plugin.getModId());
plugins.add(plugin);
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;
for (ICompatPlugin plugin : plugins) plugin.preInit();
}
public void init()
{
currPhase = Phase.INIT;
for (ICompatPlugin plugin : plugins) plugin.init();
}
public void postInit()
{
currPhase = Phase.POSTINIT;
for (ICompatPlugin plugin : plugins) plugin.postInit();
currPhase = Phase.DONE;
}
public void registerBuiltins()
{
registerPlugin(new ForgeMultiPart());
registerPlugin(new MineFactoryReloaded());
registerPlugin(new NotEnoughItems());
registerPlugin(new Waila());
}
}