Advertisement
Guest User

Teaminfo

a guest
Jun 10th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.07 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.io.BufferedReader;
  5. import java.io.BufferedWriter;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.io.PrintStream;
  10. import java.net.MalformedURLException;
  11. import java.net.Socket;
  12. import java.net.URL;
  13. import java.net.UnknownHostException;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16. import javax.imageio.ImageIO;
  17. import net.minecraft.client.Minecraft;
  18. import org.jibble.pircbot.*;
  19.  
  20. public class teaminfo extends PircBot implements Runnable
  21. {
  22. static String channel;
  23. public String username;
  24. public String nick;
  25. public String tempusr;
  26.  
  27. private static BufferedWriter bw;
  28. private boolean isRunning;
  29. boolean recievingnames;
  30. public static Map online = new HashMap();
  31. public static Map players = new HashMap();
  32.  
  33. public static Map showgui = new HashMap();
  34.  
  35. public static Map playershealth = new HashMap();
  36. public static Map playersprevhealth = new HashMap();
  37. public static Map playershunger = new HashMap();
  38. public static Map playersarmour = new HashMap();
  39.  
  40. public static Map playerpoison = new HashMap();
  41. public static Map playerfireresist = new HashMap();
  42. public static Map playerweakness = new HashMap();
  43. public static Map playerswift = new HashMap();
  44. public static Map playerslow = new HashMap();
  45. public static Map playerregen = new HashMap();
  46. public static Map playerhungerdrain = new HashMap();
  47. public static Map playeronfire = new HashMap();
  48.  
  49. public static Map playerposX = new HashMap();
  50. public static Map playerposY = new HashMap();
  51. public static Map playerposZ = new HashMap();
  52.  
  53. public static Map playerskin = new HashMap();
  54.  
  55. public static Map toplefti = new HashMap();
  56. public static Map topleftj = new HashMap();
  57. public static Map dragable = new HashMap();
  58. public static BufferedImage spowney;
  59. public static BufferedImage jay92;
  60.  
  61. public static String[] usernames;
  62. public String[] junkyarray;
  63.  
  64. public GuiScreen hello;
  65.  
  66. public GuiAddtoTeam add = new GuiAddtoTeam(hello);
  67.  
  68. int x = 0;
  69.  
  70. public teaminfo(String s)
  71. {
  72. this.nick = s;
  73. this.isRunning = true;
  74. this.recievingnames = false;
  75. this.setName(nick);
  76. this.usernames = new String[100];
  77. this.junkyarray = new String[2];
  78. }
  79.  
  80. //TODO: I need to add the ADDME thingy to the correct channel, using the PircBot classes
  81. public void onMessage(String channel, String sender, String login, String hostname, String message) {
  82.  
  83. if(message.equalsIgnoreCase("hello")) {
  84.  
  85. sendMessage(channel, sender + "Hello");
  86. }
  87. if(message.equalsIgnoreCase("PING")) {
  88.  
  89. sendMessage(channel, "PONG");
  90. }
  91. if(message.contains((" ADDME ")) && (message.contains(nick))) {
  92.  
  93. sendMessage(channel, "PRIVMSG " + add.getServerTextField() + " :" + "ADDME " + "HP" + powney.mc.thePlayer.health + "HUNGER" + powney.mc.thePlayer.foodStats.getFoodLevel() + "ARMOUR" + powney.mc.thePlayer.getTotalArmorValue() + "POISON" + powney.mc.thePlayer.isPotionActive(Potion.poison) + "FIRERESIST" + powney.mc.thePlayer.isPotionActive(Potion.fireResistance) + "WEAKNESS" + powney.mc.thePlayer.isPotionActive(Potion.weakness) + "SWIFT" + powney.mc.thePlayer.isPotionActive(Potion.digSpeed) + "SLOW" + powney.mc.thePlayer.isPotionActive(Potion.moveSlowdown) + "REGEN" + powney.mc.thePlayer.isPotionActive(Potion.regeneration) + "HUNGERDRAIN" + powney.mc.thePlayer.isPotionActive(Potion.hunger) + "ONFIRE" + powney.mc.thePlayer.isBurning() + "POSX" + (int)powney.mc.thePlayer.posX + "POSY" + (int)powney.mc.thePlayer.posY + "POSZ" + (int)powney.mc.thePlayer.posZ + "\n");
  94. }
  95. if(message.contains(("USN"))) {
  96. junkyarray = message.split("=");
  97. usernames[x++] = junkyarray[1];
  98. }
  99. }
  100.  
  101. public void onJoin(String channel, String sender, String login, String hostname)
  102. {
  103. sendMessage(channel, "USN =" + nick);
  104. }
  105.  
  106. public static void print(String s, String to)
  107. {
  108. try
  109. {
  110. // sendMessage(channel, "PRIVMSG " + to + " :" + s + "\n");
  111. }
  112. catch (Exception exception)
  113. {
  114. }
  115. }
  116.  
  117. public static void requestadd(String to) {
  118. try {
  119. // sendMessage(channel, "PRIVMSG " + to + " :" + "ADDME " + "HP" + powney.mc.thePlayer.health + "HUNGER" + powney.mc.thePlayer.foodStats.getFoodLevel() + "ARMOUR" + powney.mc.thePlayer.getTotalArmorValue() + "POISON" + powney.mc.thePlayer.isPotionActive(Potion.poison) + "FIRERESIST" + powney.mc.thePlayer.isPotionActive(Potion.fireResistance) + "WEAKNESS" + powney.mc.thePlayer.isPotionActive(Potion.weakness) + "SWIFT" + powney.mc.thePlayer.isPotionActive(Potion.digSpeed) + "SLOW" + powney.mc.thePlayer.isPotionActive(Potion.moveSlowdown) + "REGEN" + powney.mc.thePlayer.isPotionActive(Potion.regeneration) + "HUNGERDRAIN" + powney.mc.thePlayer.isPotionActive(Potion.hunger) + "ONFIRE" + powney.mc.thePlayer.isBurning() + "POSX" + (int)powney.mc.thePlayer.posX + "POSY" + (int)powney.mc.thePlayer.posY + "POSZ" + (int)powney.mc.thePlayer.posZ + "\n");
  120. }
  121. catch (Exception exception)
  122. {
  123. }
  124. }
  125.  
  126. public void acceptadd(String to) {
  127. try {
  128. int i=0;
  129. while(usernames[i]!=null) {
  130. if(usernames[i]==to) break;
  131. }
  132. if(usernames[i]!=null) {
  133. sendMessage(channel, "PRIVMSG " + usernames[i] + " :" + " ADDME " + "HP" + powney.mc.thePlayer.health + "HUNGER" + powney.mc.thePlayer.foodStats.getFoodLevel() + "ARMOUR" + powney.mc.thePlayer.getTotalArmorValue() + "POISON" + powney.mc.thePlayer.isPotionActive(Potion.poison) + "FIRERESIST" + powney.mc.thePlayer.isPotionActive(Potion.fireResistance) + "WEAKNESS" + powney.mc.thePlayer.isPotionActive(Potion.weakness) + "SWIFT" + powney.mc.thePlayer.isPotionActive(Potion.digSpeed) + "SLOW" + powney.mc.thePlayer.isPotionActive(Potion.moveSlowdown) + "REGEN" + powney.mc.thePlayer.isPotionActive(Potion.regeneration) + "HUNGERDRAIN" + powney.mc.thePlayer.isPotionActive(Potion.hunger) + "ONFIRE" + powney.mc.thePlayer.isBurning() + "POSX" + (int)powney.mc.thePlayer.posX + "POSY" + (int)powney.mc.thePlayer.posY + "POSZ" + (int)powney.mc.thePlayer.posZ + "\n");
  134. }
  135. }
  136. catch (Exception exception) {
  137. }
  138. add(to);
  139. }
  140.  
  141. public static void rejectadd(String to)
  142. {
  143. try
  144. {
  145. // sendMessage(channel, "PRIVMSG " + to + " :" + " REJECT" + "\n");
  146. }
  147. catch (Exception exception)
  148. {
  149. }
  150. }
  151.  
  152. public static void sendUpdate(String to) {
  153. try {
  154. // sendMessage(channel, "PRIVMSG " + to + " :" + " ADDME " + "HP" + powney.mc.thePlayer.health + "HUNGER" + powney.mc.thePlayer.foodStats.getFoodLevel() + "ARMOUR" + powney.mc.thePlayer.getTotalArmorValue() + "POISON" + powney.mc.thePlayer.isPotionActive(Potion.poison) + "FIRERESIST" + powney.mc.thePlayer.isPotionActive(Potion.fireResistance) + "WEAKNESS" + powney.mc.thePlayer.isPotionActive(Potion.weakness) + "SWIFT" + powney.mc.thePlayer.isPotionActive(Potion.digSpeed) + "SLOW" + powney.mc.thePlayer.isPotionActive(Potion.moveSlowdown) + "REGEN" + powney.mc.thePlayer.isPotionActive(Potion.regeneration) + "HUNGERDRAIN" + powney.mc.thePlayer.isPotionActive(Potion.hunger) + "ONFIRE" + powney.mc.thePlayer.isBurning() + "POSX" + (int)powney.mc.thePlayer.posX + "POSY" + (int)powney.mc.thePlayer.posY + "POSZ" + (int)powney.mc.thePlayer.posZ + "\n");
  155. }
  156. catch (Exception exception) {
  157. }
  158. }
  159.  
  160. public static void interpretUpdate(String update) {
  161. String name = update.substring(1, update.indexOf("!"));
  162.  
  163. String health = update.substring(update.indexOf("HP") + 2, update.indexOf("HUNGER"));
  164.  
  165. String hunger = update.substring(update.indexOf("HUNGER") + 6, update.indexOf("ARMOUR"));
  166.  
  167. String armour = update.substring(update.indexOf("ARMOUR") + 6, update.indexOf("POISON"));
  168.  
  169. String poison = update.substring(update.indexOf("POISON") + 6, update.indexOf("FIRERESIST"));
  170.  
  171. String fireresist = update.substring(update.indexOf("FIRERESIST") + 10, update.indexOf("WEAKNESS"));
  172.  
  173. String weakness = update.substring(update.indexOf("WEAKNESS") + 8, update.indexOf("SWIFT"));
  174.  
  175. String swift = update.substring(update.indexOf("SWIFT") + 5, update.indexOf("SLOW"));
  176.  
  177. String slow = update.substring(update.indexOf("SLOW") + 4, update.indexOf("REGEN"));
  178.  
  179. String regen = update.substring(update.indexOf("REGEN") + 5, update.indexOf("HUNGERDRAIN"));
  180.  
  181. String hungerdrain = update.substring(update.indexOf("HUNGERDRAIN") + 11, update.indexOf("ONFIRE"));
  182.  
  183. String onfire = update.substring(update.indexOf("ONFIRE") + 6, update.indexOf("POSX"));
  184.  
  185. String posX = update.substring(update.indexOf("POSX") + 4, update.indexOf("POSY"));
  186.  
  187. String posY = update.substring(update.indexOf("POSY") + 4, update.indexOf("POSZ"));
  188.  
  189. String posZ = update.substring(update.indexOf("POSZ") + 4);
  190.  
  191. if (playershealth.containsKey(name))
  192. {
  193. playersprevhealth.put(name, playershealth.get(name));
  194. }
  195.  
  196. playershealth.put(name, Integer.valueOf(Integer.parseInt(health)));
  197. playershunger.put(name, Integer.valueOf(Integer.parseInt(hunger)));
  198. playersarmour.put(name, Integer.valueOf(Integer.parseInt(armour)));
  199.  
  200. playerpoison.put(name, Boolean.valueOf(Boolean.parseBoolean(poison)));
  201. playerfireresist.put(name, Boolean.valueOf(Boolean.parseBoolean(fireresist)));
  202. playerweakness.put(name, Boolean.valueOf(Boolean.parseBoolean(weakness)));
  203. playerswift.put(name, Boolean.valueOf(Boolean.parseBoolean(swift)));
  204. playerslow.put(name, Boolean.valueOf(Boolean.parseBoolean(slow)));
  205. playerregen.put(name, Boolean.valueOf(Boolean.parseBoolean(regen)));
  206. playerhungerdrain.put(name, Boolean.valueOf(Boolean.parseBoolean(hungerdrain)));
  207. playeronfire.put(name, Boolean.valueOf(Boolean.parseBoolean(onfire)));
  208. playerposX.put(name, Integer.valueOf(Integer.parseInt(posX)));
  209. playerposY.put(name, Integer.valueOf(Integer.parseInt(posY)));
  210. playerposZ.put(name, Integer.valueOf(Integer.parseInt(posZ)));
  211. }
  212.  
  213. public static void add(String s)
  214. {
  215. players.put(s, Boolean.valueOf(true));
  216. showgui.put(s, Boolean.valueOf(true));
  217.  
  218. ScaledResolution scaledresolution = new ScaledResolution(powney.mc.gameSettings, powney.mc.displayWidth, powney.mc.displayHeight);
  219.  
  220. int k = scaledresolution.getScaledWidth();
  221.  
  222. toplefti.put(s, Integer.valueOf(k - 110));
  223. topleftj.put(s, Integer.valueOf(players.size() * 35));
  224.  
  225. URL skinUrl = null;
  226. try {
  227. skinUrl = new URL("http://s3.amazonaws.com/MinecraftSkins/" + s + ".png");
  228. }
  229. catch (MalformedURLException e) {
  230. e.printStackTrace();
  231. }
  232. BufferedImage bi = null;
  233. try {
  234. bi = ImageIO.read(skinUrl);
  235. }
  236. catch (IOException e) {
  237. e.printStackTrace();
  238. }
  239. playerskin.put(s, bi);
  240. }
  241.  
  242. public static void remove(String s)
  243. {
  244. players.remove(s);
  245. powney.mc.thePlayer.addChatMessage("§c" + s + "§f was removed from your team info.");
  246. try
  247. {
  248. bw.write("PRIVMSG " + s + " :" + " REMOVE " + "\n");
  249. bw.flush();
  250. }
  251. catch (Exception exception) {
  252. }
  253. }
  254.  
  255. public static void forceremove(String s) {
  256. players.remove(s);
  257. powney.mc.thePlayer.addChatMessage("§c" + s + "§f requested that you stop sharing info.");
  258. }
  259.  
  260. public void run()
  261. {
  262. URL skinUrl = null;
  263. try {
  264. skinUrl = new URL("http://s3.amazonaws.com/MinecraftSkins/" + "spowney" + ".png");
  265. }
  266. catch (MalformedURLException e) {
  267. e.printStackTrace();
  268. }
  269. try {
  270. spowney = ImageIO.read(skinUrl);
  271. }
  272. catch (IOException e) {
  273. e.printStackTrace();
  274. }
  275. try {
  276. skinUrl = new URL("http://s3.amazonaws.com/MinecraftSkins/" + "Jay_92" + ".png");
  277. }
  278. catch (MalformedURLException e) {
  279. e.printStackTrace();
  280. }
  281. try {
  282. jay92 = ImageIO.read(skinUrl);
  283. }
  284. catch (IOException e) {
  285. e.printStackTrace();
  286. }
  287.  
  288. String s = "irc.esper.net";
  289. String s1 = this.nick;
  290. channel = "#teaminfomod";
  291. System.out.println("PRIVMSG " + "rainfur" + " :" + " ADDME ");
  292. int c = 6667;
  293. try
  294. {
  295. Socket socket = new Socket(s, c);
  296. bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
  297. BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  298.  
  299. //the logging in
  300. //bw = irc.esper.net
  301. bw.write("NICK " + this.nick + "\n");
  302. bw.write("USER " + s1 + " Team Info :Team Info Mod\n");
  303. bw.flush();
  304.  
  305. //this is the RECIEVE code, not the send
  306. while (this.isRunning)
  307. {
  308. String s2 = null;
  309. while ((s2 = bufferedreader.readLine()) != null)
  310. {
  311. if (s2.contains("PING"))
  312. {
  313. bw.write("PONG " + s2.substring(s2.indexOf(":")) + "\n");
  314. bw.flush();
  315. continue;
  316. }
  317. if ((s2.contains(" ADDME ")) && (s2.contains(nick)))
  318. {
  319. String s4 = s2.substring(1, s2.indexOf("!"));
  320.  
  321. powney.mc.displayGuiScreen(new GuiAddReject(powney.mc.currentScreen, s4, s2));
  322. continue;
  323. }if ((s2.contains("REMOVE")) && (s2.contains(nick)))
  324. {
  325. String s4 = s2.substring(1, s2.indexOf("!"));
  326.  
  327. forceremove(s4);
  328. continue;
  329. }if ((s2.contains("REJECT")) && (s2.contains(nick)))
  330. {
  331. String s4 = s2.substring(1, s2.indexOf("!"));
  332. powney.mc.thePlayer.addChatMessage("Your request was rejected by §c" + s4 + "§f");
  333. continue;
  334. }if ((s2.contains(" PRIVMSG ")) && (s2.contains(nick)) && (s2.contains("UPDATE")))
  335. {
  336. String s3 = s2.substring(s2.indexOf(":", s2.indexOf("PRIVMSG")) + 1);
  337. String s4 = s2.substring(1, s2.indexOf("!"));
  338.  
  339. interpretUpdate(s2);
  340.  
  341. continue;
  342. }if ((s2.contains(" PRIVMSG ")) && (s2.contains(nick)) && (s2.contains("ADDED")))
  343. {
  344. String s3 = s2.substring(s2.indexOf(":", s2.indexOf("PRIVMSG")) + 1);
  345. String s4 = s2.substring(1, s2.indexOf("!"));
  346. powney.mc.thePlayer.addChatMessage("Your request was accepted by §c" + s4 + "§f");
  347. add(s4);
  348. interpretUpdate(s2);
  349.  
  350. continue;
  351. }if ((s2.contains(" MODE ")) && (s2.contains(nick)))
  352. {
  353. try
  354. {
  355. bw.write("JOIN " + channel + "\n");
  356. bw.flush(); } catch (Exception exception) {
  357. }
  358. continue;
  359. }
  360. if ((s2.contains(" PART ")) || (s2.contains(" QUIT ")))
  361. {
  362. String s4 = s2.substring(1, s2.indexOf("!"));
  363.  
  364. online.remove(s4);
  365. players.remove(s4);
  366.  
  367. if (players.containsKey(s4))
  368. {
  369. players.remove(s4);
  370. }
  371. continue;
  372. }
  373. if ((s2.contains(" JOIN ")) && (!s2.contains(nick)))
  374. {
  375. String s4 = s2.substring(1, s2.indexOf("!"));
  376.  
  377. online.put(s4, Boolean.valueOf(false));
  378. continue;
  379. }
  380. if (!s2.contains(" " + nick + " = " + channel + " :"))
  381. continue;
  382. String s4 = s2.substring(s2.indexOf(" :"));
  383. String[] names = s4.split(" ");
  384. for (int i = 0; i < names.length; i++)
  385. {
  386. if (names[i].startsWith("@"))
  387. {
  388. names[i] = names[i].substring(names[i].indexOf("@") + 1);
  389. }
  390. online.put(names[i], Boolean.valueOf(false));
  391. }
  392. }
  393. }
  394.  
  395. }
  396. catch (UnknownHostException unknownhostexception)
  397. {
  398. System.err.println("No such host");
  399. }
  400. catch (IOException ioexception)
  401. {
  402. System.err.println("There was an error connecting to the host");
  403. }
  404. }
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement