Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. package me.skyvox.hmod.events;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.net.HttpURLConnection;
  9. import java.net.URL;
  10.  
  11. import org.json.JSONObject;
  12.  
  13. import me.skyvox.hmod.SkyHMod;
  14. import me.skyvox.hmod.script.HypixelMultithreading;
  15. import me.skyvox.hmod.script.HypixelMultithreadingScript;
  16. import me.skyvox.hmod.utils.CheckServer;
  17. import me.skyvox.hmod.utils.chat.ChatUtil;
  18. import me.skyvox.hmod.utils.hypixelgeneralutil.AutoTip;
  19. import net.minecraft.client.Minecraft;
  20. import net.minecraft.client.entity.EntityPlayerSP;
  21. import net.minecraft.util.ChatComponentText;
  22. import net.minecraftforge.common.MinecraftForge;
  23. import net.minecraftforge.event.entity.EntityJoinWorldEvent;
  24. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  25.  
  26. public class JoinListener {
  27. public static final JoinListener INSTANCE = new JoinListener();
  28. private SkyHMod skyhmod;
  29.  
  30. @SubscribeEvent
  31. public void PlayerJoin(EntityJoinWorldEvent event) {
  32. if (event.entity instanceof EntityPlayerSP) {
  33. EntityPlayerSP player = (EntityPlayerSP) event.entity;
  34. CheckServer.check();
  35. if (CheckServer.isHypixel()) {
  36. player.addChatMessage(new ChatComponentText(ChatUtil.messageWithPre("\u00A72" + "You are on Hypixel network!")));
  37. this.onJoin();
  38.  
  39.  
  40. String raw = pullPlayerProfile(player.getName());
  41. JSONObject a = new JSONObject(raw);
  42. player.addChatMessage(new ChatComponentText("Suas vitorias sao: " + this.get(a, "player#stats#Paintball#wins")));
  43. player.addChatMessage(new ChatComponentText("Suas kills sao: " + this.get(a, "player#stats#Paintball#kills")));
  44. } else {
  45. player.addChatMessage(new ChatComponentText(ChatUtil.messageWithPre("\u00A74" + "You are not on Hypixel network, Some functions of this mod will not work.")));
  46. }
  47. }
  48.  
  49. MinecraftForge.EVENT_BUS.unregister(this);
  50. }
  51.  
  52. private void onJoin() {
  53. AutoTip.isAutoTip = true;
  54. AutoTip.autoTip();
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. /*HypixelMultithreading.runAsync(() -> {
  64. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("1"));
  65. try {
  66. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("2"));
  67. do {
  68. /*try {
  69. if (Minecraft.getMinecraft().thePlayer.getName() != null) {
  70. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("5"));
  71. break;
  72. }
  73. } catch (Exception e) {
  74.  
  75. }
  76. try {
  77. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("3"));
  78. Thread.sleep(50);
  79. } catch (InterruptedException e) {
  80. e.printStackTrace();
  81. }
  82. } while (CheckServer.isHypixel() == true);
  83. pullPlayerProfile(Minecraft.getMinecraft().thePlayer.getName());
  84. startScript();
  85. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Started"));
  86. } catch (Exception e) {
  87. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("4"));
  88. }
  89. });
  90. */
  91. }
  92.  
  93. private HypixelMultithreadingScript script;
  94. public void startScript() {
  95. HypixelMultithreading.runAsync(() -> {
  96. if (this.script != null) {
  97. this.script.stop();
  98. }
  99. this.script = new HypixelMultithreadingScript(skyhmod);
  100. this.script.run();
  101. });
  102. }
  103.  
  104.  
  105. public static String rawExpectJson(String url) {
  106. try {
  107. URL u = new URL(url);
  108. HttpURLConnection connection = (HttpURLConnection)u.openConnection();
  109. connection.setRequestMethod("GET");
  110. connection.addRequestProperty("User-Agent", "Mozilla/4.76");
  111. connection.setUseCaches(true);
  112. connection.setReadTimeout(2500);
  113. connection.setConnectTimeout(2500);
  114. connection.setDoInput(true);
  115. connection.setDoOutput(true);
  116. InputStream is = connection.getInputStream();
  117. BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  118. String line = reader.readLine();
  119. if (line != null) {
  120. StringBuilder builder = new StringBuilder(line);
  121. while (line != null) {
  122. line = reader.readLine();
  123. if (line == null) continue;
  124. builder.append(line);
  125. }
  126. reader.close();
  127. return builder.toString();
  128. }
  129. return "{}";
  130. }
  131. catch (Exception e) {
  132. return "{}";
  133. }
  134. }
  135.  
  136. public static String pullPlayerProfile(String name) {
  137. JSONObject gen_key = new JSONObject(rawExpectJson("http://sk1er.club/genkey?name=" + Minecraft.getMinecraft().thePlayer.getName() + "&uuid=" + Minecraft.getMinecraft().thePlayer.getUniqueID() + "&mcver=" + Minecraft.getMinecraft().getVersion() + "&modver=" + "1.1-Beta" + "&mod=PUBLIC_PRIVATE_MOD"));
  138. String aaaa = gen_key.getString("key");
  139. return rawExpectJson("http://sk1er.club/data/" + name + "/" + aaaa);
  140. }
  141.  
  142.  
  143. public static int get(JSONObject tmp, String path)
  144. {
  145. try
  146. {
  147. if (path.contains("#"))
  148. {
  149. int max = path.split("#").length;
  150. int cur = 0;
  151. JSONObject curent = tmp;
  152. for (String s : path.split("#"))
  153. {
  154. if (cur >= max - 1) {
  155. return curent.has(s) ? curent.getInt(s) : 0;
  156. }
  157. curent = curent.has(s) ? curent.getJSONObject(s) : new JSONObject();
  158.  
  159. cur++;
  160. }
  161. }
  162. else
  163. {
  164. return tmp.has(path) ? tmp.getInt(path) : 0;
  165. }
  166. return 0;
  167. }
  168. catch (Exception e) {}
  169. return 0;
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement