Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. package server.model.players;
  2.  
  3. import java.io.IOException;
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6. import java.text.DecimalFormat;
  7. import java.text.NumberFormat;
  8.  
  9. public class Highscores {
  10.  
  11. /**
  12. * The lock object variable.
  13. */
  14. private static Object lock = new Object();
  15.  
  16. /**
  17. * Update a player to the highscores.
  18. *
  19. * @param player
  20. * The player reference.
  21. * @param displayname
  22. * The player's display name.
  23. */
  24. public static void highscores(final Client c, final String displayname) {
  25. if (c == null) {
  26. return;
  27. }
  28. if (c.playerRights == 7) {
  29. return;
  30. }
  31. if (!requirements(c)) {
  32. return;
  33. }
  34. final int[] levels = getLevels(c);
  35. final int[] xp = getXp(c);
  36. final int total = getTotalLevel(c);
  37. final String totalxp = getTotalXp(c);
  38. String website = "";
  39. if (levels == null || xp == null || totalxp == null) {
  40. return;
  41. }
  42. try {
  43. synchronized (lock) {
  44. int rights = c.playerRights;
  45. int gamemode = 0;
  46. URL url = new URL(website
  47. + "updatehighscores.php?pass=pass&username="
  48. + c.playerName.replaceAll(" ", "_") + "&rights="
  49. + rights + "&gamemode="+gamemode+"&total=" + total + "&attack=" + levels[0]
  50. + "&defence=" + levels[1] + "&strength=" + levels[2]
  51. + "" + "&constitution=" + levels[3] + "&ranged="
  52. + levels[4] + "&prayer=" + levels[5] + "&magic="
  53. + levels[6] + "&cooking=" + levels[7] + "&woodcutting="
  54. + levels[8] + "" + "&fletching=" + levels[9]
  55. + "&fishing=" + levels[10] + "&firemaking="
  56. + levels[11] + "&crafting=" + levels[12] + "&smithing="
  57. + levels[13] + "&mining=" + levels[14] + ""
  58. + "&herblore=" + levels[15] + "&agility=" + levels[16]
  59. + "&thieving=" + levels[17] + "&slayer=" + levels[18]
  60. + "&farming=" + levels[19] + "&runecrafting="
  61. + levels[20] + "&hunter=" + levels[21] + "&totalxp="
  62. + totalxp + "&attackxp=" + xp[0] + "&defencexp="
  63. + xp[1] + "&strengthxp=" + xp[2] + ""
  64. + "&constitutionxp=" + xp[3] + "&rangedxp=" + xp[4]
  65. + "&prayerxp=" + xp[5] + "&magicxp=" + xp[6]
  66. + "&cookingxp=" + xp[7] + "&woodcuttingxp=" + xp[8]
  67. + "" + "&fletchingxp=" + xp[9] + "&fishingxp=" + xp[10]
  68. + "&firemakingxp=" + xp[11] + "&craftingxp=" + xp[12]
  69. + "&smithingxp=" + xp[13] + "&miningxp=" + xp[14] + ""
  70. + "&herblorexp=" + xp[15] + "&agilityxp=" + xp[16]
  71. + "&thievingxp=" + xp[17] + "&slayerxp=" + xp[18]
  72. + "&farmingxp=" + xp[19] + "&runecraftingxp=" + xp[20]);
  73. //System.out.println(url);
  74. url.openStream().close();
  75. }
  76. } catch (MalformedURLException e) {
  77. e.printStackTrace();
  78. } catch (IOException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82.  
  83. /**
  84. * Check if the player has the requirements to be on the highscores.
  85. *
  86. * @param player
  87. * The player reference.
  88. * @return If the player has the requirements {@code true}.
  89. */
  90. private static boolean requirements(Client c) {
  91. /*
  92. * if(getTotalLevel(c) < 300) return false;
  93. */
  94. return true;
  95. }
  96.  
  97. /**
  98. * Get all the player's levels.
  99. *
  100. * @param player
  101. * The player refrence.
  102. * @return A short array containing all the player's levels.
  103. */
  104. private static int[] getLevels(Client c) {
  105. return c.playerLevel;
  106. }
  107.  
  108. /**
  109. * Get the player's total level.
  110. *
  111. * @param player
  112. * The player reference.
  113. * @return The player's total level.
  114. */
  115. private static int getTotalLevel(Client c) {
  116. int totallevel = 0;
  117. for (int i = 0; i <= 20; i++) {
  118. totallevel += c.getLevelForXP(c.playerXP[i]);
  119. }
  120. return totallevel;
  121. }
  122.  
  123. /**
  124. * Get all the player's experience in a double array.
  125. *
  126. * @param player
  127. * The player reference.
  128. * @return All the player's experience in a double array.
  129. */
  130. private static int[] getXp(Client c) {
  131. return c.playerXP;
  132. }
  133.  
  134. /**
  135. * Get the player's total experience.
  136. *
  137. * @param player
  138. * The player reference.
  139. * @return The player's total experience.
  140. */
  141. private static String getTotalXp(Client c) {
  142. double totalxp = 0;
  143. for (double xp : c.playerXP) {
  144. totalxp += xp;
  145. }
  146. NumberFormat formatter = new DecimalFormat("#######");
  147. return formatter.format(totalxp);
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement