/src/main/java/me/rigamortis/seppuku/Seppuku.java

https://github.com/seppukudevelopment/seppuku · Java · 395 lines · 299 code · 78 blank · 18 comment · 54 complexity · 41077fe503b6a6da87b171a2f973cf93 MD5 · raw file

  1. package me.rigamortis.seppuku;
  2. import me.rigamortis.seppuku.api.event.client.EventLoad;
  3. import me.rigamortis.seppuku.api.event.client.EventReload;
  4. import me.rigamortis.seppuku.api.event.client.EventUnload;
  5. import me.rigamortis.seppuku.api.logging.SeppukuFormatter;
  6. import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor;
  7. import me.rigamortis.seppuku.impl.gui.menu.GuiSeppukuMainMenu;
  8. import me.rigamortis.seppuku.impl.management.*;
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.util.text.ITextComponent;
  11. import net.minecraft.util.text.TextComponentString;
  12. import net.minecraftforge.fml.common.Loader;
  13. import net.minecraftforge.fml.common.ModContainer;
  14. import team.stiff.pomelo.EventManager;
  15. import team.stiff.pomelo.impl.annotated.AnnotatedEventManager;
  16. import java.util.logging.ConsoleHandler;
  17. import java.util.logging.Logger;
  18. /**
  19. * @author Seth (riga)
  20. * @author noil
  21. * @author github contributors
  22. */
  23. public final class Seppuku {
  24. public static final Seppuku INSTANCE = new Seppuku();
  25. private Logger logger;
  26. //private String prevTitle;
  27. private EventManager eventManager;
  28. private APIManager apiManager;
  29. private ModuleManager moduleManager;
  30. private CommandManager commandManager;
  31. private FriendManager friendManager;
  32. private ConfigManager configManager;
  33. private RotationManager rotationManager;
  34. private MacroManager macroManager;
  35. private WaypointManager waypointManager;
  36. private TickRateManager tickRateManager;
  37. private ChatManager chatManager;
  38. private WorldManager worldManager;
  39. private IgnoredManager ignoredManager;
  40. private CapeManager capeManager;
  41. private PositionManager positionManager;
  42. private JoinLeaveManager joinLeaveManager;
  43. private HudManager hudManager;
  44. private AnimationManager animationManager;
  45. private NotificationManager notificationManager;
  46. private GuiHudEditor hudEditor;
  47. private GuiSeppukuMainMenu seppukuMainMenu;
  48. private CameraManager cameraManager;
  49. private AltManager altManager;
  50. private ShaderManager shaderManager;
  51. /**
  52. * The initialization point of the client
  53. * this is called post launch
  54. */
  55. public void init() {
  56. this.eventManager = new AnnotatedEventManager();
  57. this.apiManager = new APIManager();
  58. this.configManager = new ConfigManager();
  59. this.ignoredManager = new IgnoredManager();
  60. this.friendManager = new FriendManager();
  61. this.rotationManager = new RotationManager();
  62. this.macroManager = new MacroManager();
  63. this.waypointManager = new WaypointManager();
  64. this.tickRateManager = new TickRateManager();
  65. this.chatManager = new ChatManager();
  66. this.worldManager = new WorldManager();
  67. this.capeManager = new CapeManager();
  68. this.positionManager = new PositionManager();
  69. this.joinLeaveManager = new JoinLeaveManager();
  70. this.animationManager = new AnimationManager();
  71. this.notificationManager = new NotificationManager();
  72. this.moduleManager = new ModuleManager();
  73. this.commandManager = new CommandManager();
  74. this.cameraManager = new CameraManager();
  75. this.altManager = new AltManager();
  76. this.shaderManager = new ShaderManager();
  77. this.hudManager = new HudManager();
  78. this.hudEditor = new GuiHudEditor();
  79. this.seppukuMainMenu = new GuiSeppukuMainMenu();
  80. this.configManager.init(); // Keep last, so we load configs after everything else inits
  81. //this.prevTitle = Display.getTitle();
  82. //Display.setTitle("Seppuku 1.12.2");
  83. this.getEventManager().dispatchEvent(new EventLoad());
  84. // Add runtime hook to listen for shutdown to save configs
  85. Runtime.getRuntime().addShutdownHook(new Thread("Seppuku Shutdown Hook") {
  86. @Override
  87. public void run() {
  88. getConfigManager().saveAll();
  89. }
  90. });
  91. }
  92. public void errorChat(String message) {
  93. Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247c " + message));
  94. }
  95. public void errorfChat(String format, Object... objects) {
  96. errorChat(String.format(format, objects));
  97. }
  98. public void logChat(String message) {
  99. Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247f " + message));
  100. }
  101. public void logcChat(ITextComponent textComponent) {
  102. Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247f ").appendSibling(textComponent));
  103. }
  104. public void logfChat(String format, Object... objects) {
  105. logChat(String.format(format, objects));
  106. }
  107. public void unload() {
  108. this.moduleManager.unload();
  109. this.apiManager.unload();
  110. this.commandManager.unload();
  111. this.friendManager.unload();
  112. this.waypointManager.unload();
  113. this.macroManager.unload();
  114. this.tickRateManager.unload();
  115. this.chatManager.unload();
  116. this.ignoredManager.unload();
  117. this.capeManager.unload();
  118. this.joinLeaveManager.unload();
  119. this.hudManager.unload();
  120. this.animationManager.unload();
  121. this.notificationManager.unload();
  122. this.hudEditor.unload();
  123. this.seppukuMainMenu.unload();
  124. this.cameraManager.unload();
  125. this.altManager.unload();
  126. this.shaderManager.unload();
  127. this.getEventManager().dispatchEvent(new EventUnload());
  128. ModContainer seppukuModContainer = null;
  129. for (ModContainer modContainer : Loader.instance().getActiveModList()) {
  130. if (modContainer.getModId().equals("seppukumod")) {
  131. seppukuModContainer = modContainer;
  132. }
  133. }
  134. if (seppukuModContainer != null) {
  135. Loader.instance().getActiveModList().remove(seppukuModContainer);
  136. }
  137. //Display.setTitle(this.prevTitle);
  138. Minecraft.getMinecraft().ingameGUI.getChatGUI().clearChatMessages(true);
  139. System.gc();
  140. }
  141. //TODO fix multi event firing when reloading modules
  142. public void reload() {
  143. this.waypointManager.getWaypointDataList().clear();
  144. this.friendManager.getFriendList().clear();
  145. this.macroManager.getMacroList().clear();
  146. this.worldManager.getWorldDataList().clear();
  147. this.ignoredManager.getIgnoredList().clear();
  148. this.shaderManager.reload();
  149. this.capeManager.getCapeUserList().clear();
  150. this.capeManager.getCapesMap().clear();
  151. this.capeManager = new CapeManager();
  152. this.configManager.getConfigurableList().clear();
  153. this.configManager = new ConfigManager();
  154. this.configManager.init();
  155. this.getEventManager().dispatchEvent(new EventReload());
  156. }
  157. /**
  158. * Setup a logger and set the format
  159. */
  160. private void initLogger() {
  161. this.logger = Logger.getLogger(Seppuku.class.getName());
  162. logger.setUseParentHandlers(false);
  163. final ConsoleHandler handler = new ConsoleHandler();
  164. handler.setFormatter(new SeppukuFormatter());
  165. logger.addHandler(handler);
  166. }
  167. public Logger getLogger() {
  168. if (this.logger == null) {
  169. this.initLogger();
  170. }
  171. return this.logger;
  172. }
  173. public EventManager getEventManager() {
  174. if (this.eventManager == null) {
  175. this.eventManager = new AnnotatedEventManager();
  176. }
  177. return this.eventManager;
  178. }
  179. public APIManager getApiManager() {
  180. if (this.apiManager == null) {
  181. this.apiManager = new APIManager();
  182. }
  183. return this.apiManager;
  184. }
  185. public ModuleManager getModuleManager() {
  186. if (this.moduleManager == null) {
  187. this.moduleManager = new ModuleManager();
  188. }
  189. return this.moduleManager;
  190. }
  191. public CommandManager getCommandManager() {
  192. if (this.commandManager == null) {
  193. this.commandManager = new CommandManager();
  194. }
  195. return this.commandManager;
  196. }
  197. public FriendManager getFriendManager() {
  198. if (this.friendManager == null) {
  199. this.friendManager = new FriendManager();
  200. }
  201. return this.friendManager;
  202. }
  203. public ConfigManager getConfigManager() {
  204. if (this.configManager == null) {
  205. this.configManager = new ConfigManager();
  206. }
  207. return this.configManager;
  208. }
  209. public RotationManager getRotationManager() {
  210. if (this.rotationManager == null) {
  211. this.rotationManager = new RotationManager();
  212. }
  213. return this.rotationManager;
  214. }
  215. public MacroManager getMacroManager() {
  216. if (this.macroManager == null) {
  217. this.macroManager = new MacroManager();
  218. }
  219. return this.macroManager;
  220. }
  221. public WaypointManager getWaypointManager() {
  222. if (this.waypointManager == null) {
  223. this.waypointManager = new WaypointManager();
  224. }
  225. return this.waypointManager;
  226. }
  227. public TickRateManager getTickRateManager() {
  228. if (this.tickRateManager == null) {
  229. this.tickRateManager = new TickRateManager();
  230. }
  231. return this.tickRateManager;
  232. }
  233. public ChatManager getChatManager() {
  234. if (this.chatManager == null) {
  235. this.chatManager = new ChatManager();
  236. }
  237. return this.chatManager;
  238. }
  239. public WorldManager getWorldManager() {
  240. if (this.worldManager == null) {
  241. this.worldManager = new WorldManager();
  242. }
  243. return this.worldManager;
  244. }
  245. public IgnoredManager getIgnoredManager() {
  246. if (this.ignoredManager == null) {
  247. this.ignoredManager = new IgnoredManager();
  248. }
  249. return this.ignoredManager;
  250. }
  251. public CapeManager getCapeManager() {
  252. if (this.capeManager == null) {
  253. this.capeManager = new CapeManager();
  254. }
  255. return this.capeManager;
  256. }
  257. public PositionManager getPositionManager() {
  258. if (this.positionManager == null) {
  259. this.positionManager = new PositionManager();
  260. }
  261. return this.positionManager;
  262. }
  263. public JoinLeaveManager getJoinLeaveManager() {
  264. if (this.joinLeaveManager == null) {
  265. this.joinLeaveManager = new JoinLeaveManager();
  266. }
  267. return this.joinLeaveManager;
  268. }
  269. public HudManager getHudManager() {
  270. if (this.hudManager == null) {
  271. this.hudManager = new HudManager();
  272. }
  273. return this.hudManager;
  274. }
  275. public AnimationManager getAnimationManager() {
  276. if (this.animationManager == null) {
  277. this.animationManager = new AnimationManager();
  278. }
  279. return this.animationManager;
  280. }
  281. public NotificationManager getNotificationManager() {
  282. if (this.notificationManager == null) {
  283. this.notificationManager = new NotificationManager();
  284. }
  285. return this.notificationManager;
  286. }
  287. public GuiHudEditor getHudEditor() {
  288. if (this.hudEditor == null) {
  289. this.hudEditor = new GuiHudEditor();
  290. }
  291. return this.hudEditor;
  292. }
  293. public GuiSeppukuMainMenu getSeppukuMainMenu() {
  294. if (this.seppukuMainMenu == null) {
  295. this.seppukuMainMenu = new GuiSeppukuMainMenu();
  296. }
  297. return this.seppukuMainMenu;
  298. }
  299. public CameraManager getCameraManager() {
  300. if (this.cameraManager == null) {
  301. this.cameraManager = new CameraManager();
  302. }
  303. return this.cameraManager;
  304. }
  305. public AltManager getAltManager() {
  306. if (this.altManager == null) {
  307. this.altManager = new AltManager();
  308. }
  309. return this.altManager;
  310. }
  311. public ShaderManager getShaderManager() {
  312. if (this.shaderManager == null) {
  313. this.shaderManager = new ShaderManager();
  314. }
  315. return this.shaderManager;
  316. }
  317. }