Advertisement
armark1ng

Untitled

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