Advertisement
Guest User

Untitled

a guest
Feb 15th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3. import java.util.Vector;
  4.  
  5. public class hiscores
  6. {
  7. public static final String searchURL = "http://hiscore.runescape.com/index_lite.ws?player=";
  8. public static final String[] skillName = {"Overall", "Attack", "Defence", "Strength",
  9. "Constitution", "Ranged", "Prayer", "Magic",
  10. "Cooking", "Woodcutting", "Fletching", "Fishing",
  11. "Firemaking", "Crafting", "Smithing", "Mining",
  12. "Herblore", "Agility", "Thieving", "Slayer",
  13. "Farming", "Runecrafting", "Hunter", "Construction",
  14. "Summoning", "Dungeoneering", "Duel Tournament",
  15. "Bounty Hunters", "Bounty Hunter Rogues",
  16. "Fist of Guthix", "Mobilising Armies",
  17. "B.A Attackers", "B.A Defenders", "B.A Collectors",
  18. "B.A Healers", "Castle Wars Games", "Conquest"};
  19. public static final String[] skillDataName = {"Rank", "Level", "Experience"};
  20. public static final int expVSize = skillName.length;
  21.  
  22. public static void main(String[] args)
  23. {
  24. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  25. String keyboard = "";
  26.  
  27. while(true)
  28. {
  29. System.out.print("Enter rs name: ");
  30. try
  31. {
  32. keyboard = br.readLine();
  33. if(keyboard.compareTo("`exit") == 0)
  34. break;
  35. }
  36. catch(Exception e)
  37. {
  38. System.out.println("Threw a " + e.getClass() + " with message " + e.getMessage());
  39. }
  40. System.out.println();
  41.  
  42. try
  43. {
  44. System.out.println("Looking up hiscores . . .");
  45. Vector stats = getHiscores(keyboard);
  46. System.out.println("Found player!");
  47. System.out.print(rHiscoresToString(stats));
  48. }
  49. catch(FileNotFoundException e)
  50. {
  51. System.out.println("User not found.");
  52. }
  53. catch(Exception e)
  54. {
  55. System.out.println("Threw a " + e.getClass() + " with message " + e.getMessage());
  56. }
  57. }
  58. }
  59.  
  60. public static String rHiscoresToString(Vector data)
  61. {
  62. String formatted = "";
  63. for(int i = 0; i < expVSize; i++)
  64. {
  65. String[] get = (String[])data.get(i);
  66.  
  67. formatted = formatted + "[" + skillName[i] + "] ";
  68. for(int i2 = 0; i2 < get.length; i2++)
  69. {
  70. formatted = formatted + skillDataName[i2] + ": " + get[i2] + " || ";
  71. }
  72.  
  73. formatted = formatted + "\n";
  74. }
  75.  
  76. return formatted;
  77. }
  78.  
  79. public static Vector getHiscores(String rsname) throws Exception
  80. {
  81. Vector data = new Vector(expVSize);
  82. URL resultsURL = new URL(searchURL + rsname);
  83. BufferedReader resultsBuffer = new BufferedReader(new InputStreamReader(resultsURL.openStream()));
  84.  
  85. String current = "";
  86. while((current = resultsBuffer.readLine()) != null)
  87. {
  88. data.add(current.split(","));
  89. }
  90.  
  91. resultsBuffer.close();
  92. return data;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement