Advertisement
armark1ng

Untitled

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