Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. package me.deftware.aristois.event;
  2.  
  3. import com.google.gson.JsonArray;
  4. import com.google.gson.JsonElement;
  5. import com.google.gson.JsonPrimitive;
  6. import me.deftware.aristois.events.EventUpdateFast;
  7. import me.deftware.aristois.gui.modgui.ModGui;
  8. import me.deftware.aristois.mod.mods.movement.Blink;
  9. import me.deftware.aristois.util.MacroManager;
  10. import me.deftware.client.framework.event.EventListener;
  11. import me.deftware.client.framework.event.events.*;
  12. import me.deftware.client.framework.maps.SettingsMap;
  13. import me.deftware.client.framework.utils.ChatColor;
  14.  
  15. import java.awt.*;
  16.  
  17. import lombok.Setter;
  18. import me.deftware.aristois.main.Client;
  19. import me.deftware.aristois.gui.IGuiClientOptions;
  20. import me.deftware.aristois.gui.IGuiMainMenu;
  21. import me.deftware.aristois.main.Main;
  22. import me.deftware.aristois.mod.mods.render.Waypoints;
  23. import me.deftware.aristois.util.ChatUtils;
  24. import me.deftware.aristois.util.WaypointsManager;
  25. import me.deftware.aristois.util.WaypointsManager.Waypoint;
  26. import me.deftware.client.framework.event.Event;
  27. import me.deftware.client.framework.event.events.EventGuiScreenDisplay.ScreenTypes;
  28. import me.deftware.client.framework.event.events.EventGuiScreenDraw.CommonScreenTypes;
  29. import me.deftware.client.framework.utils.RenderUtils;
  30. import me.deftware.client.framework.wrappers.IChat;
  31. import me.deftware.client.framework.wrappers.IMinecraft;
  32. import me.deftware.client.framework.wrappers.entity.IEntity;
  33. import me.deftware.client.framework.wrappers.entity.IEntity.EntityType;
  34. import me.deftware.client.framework.wrappers.entity.IEntityPlayer;
  35. import me.deftware.client.framework.wrappers.gui.IGuiButton;
  36. import me.deftware.client.framework.wrappers.gui.IGuiInventory;
  37. import me.deftware.client.framework.wrappers.gui.IGuiScreen;
  38. import me.deftware.client.framework.wrappers.gui.IScreens.Screen;
  39. import me.deftware.client.framework.wrappers.world.IWorld;
  40. import org.lwjgl.glfw.GLFW;
  41.  
  42. public class EventBus extends EventListener {
  43.  
  44. private static IGuiScreen iScreen = null;
  45. private static Screen screenType = null;
  46.  
  47. @Setter
  48. private static String invsee = "";
  49.  
  50. public static void onEvent(Event event) {
  51. if (Client.getInstance().getModloader().isLoaded()) {
  52. Client.getInstance().getModloader().getMods().forEach((key, mod) -> {
  53. if (mod.isEnabled()) {
  54. mod.onEvent(event);
  55. } else if (mod.getName().equals("Blink") && event instanceof EventUpdate && ((Blink) mod).flag) {
  56. mod.onEvent(event);
  57. }
  58. });
  59. }
  60. if (event instanceof EventRender2D || event instanceof EventRender3D) {
  61. RenderUtils.fixDarkLight();
  62. }
  63. if (event instanceof EventUpdateFast && IMinecraft.getIScreen() != null && IMinecraft.getIScreen() instanceof ModGui) {
  64. ((ModGui) IMinecraft.getIScreen()).onTick();
  65. }
  66. if (event instanceof EventChatSend) {
  67. EventChatSend e = (EventChatSend) event;
  68. if (e.getMessage().contains(" && ")) {
  69. event.setCanceled(true);
  70. for (String cmd : e.getMessage().split(" && ")) {
  71. IChat.sendChatMessage(cmd);
  72. }
  73. }
  74. } else if (event instanceof EventChatReceive) {
  75. JsonArray usernames = Main.getConfig().getArray("user_ignore_list");
  76. String msg = ((EventChatReceive) event).getMessage().toLowerCase();
  77. if (msg.contains(" ")) {
  78. for (JsonElement username : usernames) {
  79. if (msg.contains(username.getAsString().toLowerCase())) {
  80. event.setCanceled(true);
  81. break;
  82. }
  83. }
  84. } else {
  85. // This shouldn't happen but oh well
  86. event.setCanceled(usernames.contains(new JsonPrimitive(msg)));
  87. }
  88. } else if (event instanceof EventKeyAction) {
  89. Client.getInstance().getModloader().getMods().forEach((key, mod) -> {
  90. if (mod.getKeybind() == ((EventKeyAction) event).getKeyCode() && mod.getKeybind() != GLFW.GLFW_KEY_UNKNOWN) {
  91. mod.toggle();
  92. }
  93. });
  94. MacroManager.getInstance().processMacro((EventKeyAction) event);
  95. } else if (event instanceof EventRender2D) {
  96. checkForScreens();
  97. if (!invsee.equals("")) {
  98. IEntity e = null;
  99. for (IEntity entity : IWorld.getILoadedEntityList()) {
  100. if (!entity.isPlayer()) { continue; }
  101. if (entity.getName().toLowerCase().equals(invsee.toLowerCase())) {
  102. if (entity.instanceOf(EntityType.EntityOtherPlayerMP)) {
  103. e = entity;
  104. }
  105. break;
  106. }
  107. }
  108. if (e == null) {
  109. ChatUtils.sendClientMessage("Could not find the specified player");
  110. } else {
  111. ChatUtils.sendClientMessage("Opening inventory for player " + invsee);
  112. IMinecraft.openInventory(new IGuiInventory(e));
  113. }
  114. invsee = "";
  115. }
  116. } else if (event instanceof EventGuiScreenDisplay) {
  117. EventGuiScreenDisplay gEvent = (EventGuiScreenDisplay) event;
  118. if (gEvent.getType().equals(ScreenTypes.MainMenu)) {
  119. gEvent.setScreen(new IGuiMainMenu());
  120. }
  121. } else if (event instanceof EventIRCMessage) {
  122. String message = ((EventIRCMessage) event).getMessage();
  123. if (Client.getInstance().getIrc() == null) {
  124. ChatUtils.sendClientMessage("You are not connected to the IRC");
  125. return;
  126. } else if (!Client.getInstance().getIrc().isConnected()) {
  127. ChatUtils.sendClientMessage("You are not connected to the IRC");
  128. return;
  129. }
  130. if (message.equals("quit")) {
  131. Client.getInstance().getIrc().disconnect();
  132. return;
  133. }
  134. Client.getInstance().getIrc().onInput(message);
  135. return;
  136. } else if (event instanceof EventGameOver) {
  137. if (Client.getInstance().getModloader().getMod(Waypoints.class).isDeathpoints()) {
  138. Waypoint p = new Waypoint("Death", (int) IEntityPlayer.getPosX(), (int) IEntityPlayer.getPosY(),
  139. (int) IEntityPlayer.getPosZ(), WaypointsManager.getInstance().getServerSave(), Color.pink.getRGB(), true);
  140. WaypointsManager.getInstance().addWaypoint(p);
  141. ChatUtils.sendClientMessage("Created death waypoint");
  142. }
  143. } else if (event instanceof EventGuiScreenDraw) {
  144. drawMenuButton((EventGuiScreenDraw) event);
  145. } else if (event instanceof EventServerPinged) {
  146. String version = ((EventServerPinged) event).getGameVersion();
  147. ((EventServerPinged) event)
  148. .setPopulationInfo(ChatColor.AQUA + "" + version + " " + ChatColor.GRAY + "| " + ((EventServerPinged) event).getPopulationInfo());
  149. } else if (event instanceof EventChatboxType) {
  150. if (!Main.getConfig().getBool("chat-overlay", true)) {
  151. return;
  152. }
  153. EventChatboxType e = (EventChatboxType) event;
  154. if (e.getText().equals("")) {
  155. e.setOverlay("# <Message> - Sends an IRC message | " + (String) SettingsMap.getValue(SettingsMap.MapKeys.EMC_SETTINGS, "COMMAND_TRIGGER", ".") + "help - View all " + Main.getName() + " commands");
  156. } else {
  157. e.setOverlay("");
  158. }
  159. }
  160. }
  161.  
  162. public static void checkForScreens() {
  163. if (iScreen != null) {
  164. IMinecraft.setGuiScreen(iScreen);
  165. iScreen = null;
  166. }
  167. if (screenType != null) {
  168. IMinecraft.setGuiScreenType(screenType);
  169. screenType = null;
  170. }
  171. }
  172.  
  173. public static void setScreen(IGuiScreen screen) {
  174. EventBus.iScreen = screen;
  175. }
  176.  
  177. public static void setScreenType(Screen screen) {
  178. EventBus.screenType = screen;
  179. }
  180.  
  181. private static void drawMenuButton(EventGuiScreenDraw event) {
  182. if (event.instanceOf(CommonScreenTypes.GuiIngameMenu)) {
  183. if (event.getIButtonList().isEmpty()) {
  184. event.addButton(new IGuiButton(30, event.getWidth() / 2 - 100, event.getHeight() / 4 + 56,
  185. Main.getName() + " Options") {
  186. @Override
  187. public void onButtonClick(double mouseX, double mouseY) {
  188. IMinecraft.setGuiScreen(new IGuiClientOptions());
  189. }
  190. });
  191. }
  192. }
  193. }
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement