Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.model.players;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- public class Highscores {
- /**
- * The lock object variable.
- */
- private static Object lock = new Object();
- /**
- * Update a player to the highscores.
- *
- * @param player
- * The player reference.
- * @param displayname
- * The player's display name.
- */
- public static void highscores(final Client c, final String displayname) {
- if (c == null) {
- return;
- }
- if (c.playerRights == 7) {
- return;
- }
- if (!requirements(c)) {
- return;
- }
- final int[] levels = getLevels(c);
- final int[] xp = getXp(c);
- final int total = getTotalLevel(c);
- final String totalxp = getTotalXp(c);
- String website = "";
- if (levels == null || xp == null || totalxp == null) {
- return;
- }
- final int rights = c.playerRights;
- final int gamemode = 0;
- try {
- synchronized (lock) {
- URL url = new URL(website + "updatehighscores.php?pass=pass&username="
- + c.playerName.replaceAll(" ", "_") + "&rights=" + rights + "&gamemode=" + gamemode + "&total="
- + total + "&attack=" + levels[0] + "&defence=" + levels[1] + "&strength=" + levels[2] + ""
- + "&constitution=" + levels[3] + "&ranged=" + levels[4] + "&prayer=" + levels[5] + "&magic="
- + levels[6] + "&cooking=" + levels[7] + "&woodcutting=" + levels[8] + "" + "&fletching="
- + levels[9] + "&fishing=" + levels[10] + "&firemaking=" + levels[11] + "&crafting=" + levels[12]
- + "&smithing=" + levels[13] + "&mining=" + levels[14] + "" + "&herblore=" + levels[15]
- + "&agility=" + levels[16] + "&thieving=" + levels[17] + "&slayer=" + levels[18] + "&farming="
- + levels[19] + "&runecrafting=" + levels[20] + "&hunter=" + levels[21] + "&totalxp=" + totalxp
- + "&attackxp=" + xp[0] + "&defencexp=" + xp[1] + "&strengthxp=" + xp[2] + ""
- + "&constitutionxp=" + xp[3] + "&rangedxp=" + xp[4] + "&prayerxp=" + xp[5] + "&magicxp=" + xp[6]
- + "&cookingxp=" + xp[7] + "&woodcuttingxp=" + xp[8] + "" + "&fletchingxp=" + xp[9]
- + "&fishingxp=" + xp[10] + "&firemakingxp=" + xp[11] + "&craftingxp=" + xp[12] + "&smithingxp="
- + xp[13] + "&miningxp=" + xp[14] + "" + "&herblorexp=" + xp[15] + "&agilityxp=" + xp[16]
- + "&thievingxp=" + xp[17] + "&slayerxp=" + xp[18] + "&farmingxp=" + xp[19] + "&runecraftingxp="
- + xp[20] + "&hunterxp=" + xp[21] + "&construction=" + levels[22] + "&summoning=" + levels[23]
- + "&dungeoneering=" + levels[24] + "&summoningxp=" + xp[23] + "&constructionxp=" + xp[22]
- + "&dungeoneering=" + levels[24]);
- // System.out.println(url);
- url.openStream().close();
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Check if the player has the requirements to be on the highscores.
- *
- * @param player
- * The player reference.
- * @return If the player has the requirements {@code true}.
- */
- private static boolean requirements(Client c) {
- /*
- * if(getTotalLevel(c) < 300) return false;
- */
- return true;
- }
- /**
- * Get all the player's levels.
- *
- * @param player
- * The player refrence.
- * @return A short array containing all the player's levels.
- */
- private static int[] getLevels(Client c) {
- return c.playerLevel;
- }
- /**
- * Get the player's total level.
- *
- * @param player
- * The player reference.
- * @return The player's total level.
- */
- private static int getTotalLevel(Client c) {
- int totallevel = 0;
- for (int i = 0; i <= 24; i++) {
- totallevel += c.getLevelForXP(c.playerXP[i]);
- }
- return totallevel;
- }
- /**
- * Get all the player's experience in a double array.
- *
- * @param player
- * The player reference.
- * @return All the player's experience in a double array.
- */
- private static int[] getXp(Client c) {
- return c.playerXP;
- }
- /**
- * Get the player's total experience.
- *
- * @param player
- * The player reference.
- * @return The player's total experience.
- */
- private static String getTotalXp(Client c) {
- double totalxp = 0;
- for (double xp : c.playerXP) {
- totalxp += xp;
- }
- NumberFormat formatter = new DecimalFormat("#######");
- return formatter.format(totalxp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement