daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Oct 22nd, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rs2hd;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. import com.rs2hd.model.PlayerDetails;
  10. import com.rs2hd.model.Skills;
  11. import com.rs2hd.model.Player;
  12.  
  13. public class Hiscores {
  14.  
  15.     public static Connection con = null;
  16.     public static Statement stmt;
  17.     public static boolean connectionMade;
  18.  
  19.     public static void createConnection() {
  20.         try {
  21.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  22.         String IP="184.22.145.77";
  23.         String DB="runeunit_highscores";
  24.         String User="runeunit_scores";
  25.         String Pass="gears2pwnage";
  26.             con = DriverManager.getConnection("jdbc:mysql://"+IP+"/"+DB, User, Pass);
  27.             stmt = con.createStatement();
  28.  //System.out.println("Connection to SQL database successful!");
  29.         } catch (Exception e) {
  30.         System.out.println("Connection to SQL database failed");
  31.         e.printStackTrace();
  32.         }
  33.     }
  34.  
  35.  
  36.     public static ResultSet query(String s) throws SQLException {
  37.         try {
  38.             if (s.toLowerCase().startsWith("select")) {
  39.                 ResultSet rs = stmt.executeQuery(s);
  40.                 return rs;
  41.             } else {
  42.                 stmt.executeUpdate(s);
  43.             }
  44.             return null;
  45.         } catch (Exception e) {
  46.             destroyConnection();
  47.         }
  48.         return null;
  49.     }
  50.  
  51.     public static void destroyConnection() {
  52.         try {
  53.             stmt.close();
  54.             con.close();
  55.         } catch (Exception e) {
  56.         }
  57.     }
  58.  
  59.     public static boolean saveHighScore(Player player) {
  60.         try {
  61.             Skills skills = player.getSkills();
  62.             int[] overall = getOverall(player);
  63.             query("DELETE FROM `skills` WHERE playerName = '"+player.getDisplayName()+"';");
  64.             query("DELETE FROM `skillsoverall` WHERE playerName = '"+player.getDisplayName()+"';");
  65.             if(player.getRights() == 2) {
  66.                 return true;
  67.             }
  68.             query("INSERT INTO `skills` (`playerName`,`Attacklvl`,`Attackxp`,`Defencelvl`,`Defencexp`,`Strengthlvl`,`Strengthxp`,`Hitpointslvl`,`Hitpointsxp`,`Rangelvl`,`Rangexp`,`Prayerlvl`,`Prayerxp`,`Magiclvl`,`Magicxp`,`Cookinglvl`,`Cookingxp`,`Woodcuttinglvl`,`Woodcuttingxp`,`Fletchinglvl`,`Fletchingxp`,`Fishinglvl`,`Fishingxp`,`Firemakinglvl`,`Firemakingxp`,`Craftinglvl`,`Craftingxp`,`Smithinglvl`,`Smithingxp`,`Mininglvl`,`Miningxp`,`Herblorelvl`,`Herblorexp`,`Agilitylvl`,`Agilityxp`,`Thievinglvl`,`Thievingxp`,`Slayerlvl`,`Slayerxp`,`Farminglvl`,`Farmingxp`,`Runecraftlvl`,`Runecraftxp`, `Hunterlvl`, `Hunterxp`, `Constructionlvl`, `Constructionxp`, `Summoninglvl`, `Summoningxp`) VALUES ('"+player.getDisplayName()+"',"+skills.getLevel(0)+","+skills.getXp(0)+","+skills.getLevel(1)+","+skills.getXp(1)+","+skills.getLevel(2)+","+skills.getXp(2)+","+skills.getLevel(3)+","+skills.getXp(3)+","+skills.getLevel(4)+","+skills.getXp(4)+","+skills.getLevel(5)+","+skills.getXp(5)+","+skills.getLevel(6)+","+skills.getXp(6)+","+skills.getLevel(7)+","+skills.getXp(7)+","+skills.getLevel(8)+","+skills.getXp(8)+","+skills.getLevel(9)+","+skills.getXp(9)+","+skills.getLevel(10)+","+skills.getXp(10)+","+skills.getLevel(11)+","+skills.getXp(11)+","+skills.getLevel(12)+","+skills.getXp(12)+","+skills.getLevel(13)+","+skills.getXp(13)+","+skills.getLevel(14)+","+skills.getXp(14)+","+skills.getLevel(15)+","+skills.getXp(15)+","+skills.getLevel(16)+","+skills.getXp(16)+","+skills.getLevel(17)+","+skills.getXp(17)+","+skills.getLevel(18)+","+skills.getXp(18)+","+skills.getLevel(19)+","+skills.getXp(19)+","+skills.getLevel(20)+","+skills.getXp(20)+"," + skills.getLevel(21)+"," + skills.getXp(21) + "," +skills.getLevel(22) + "," + skills.getXp(22) + "," + skills.getLevel(23) + "," + skills.getXp(23)+");");
  69.             query("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('"+player.getDisplayName()+"'," + overall[0] +"," + overall[1] +");");
  70.             //query("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('"+player.getDisplayName()+"',"+(skills.getLevelForXp(0) + skills.getLevelForXp(1) + skills.getLevelForXp(2) + skills.getLevelForXp(3) + skills.getLevelForXp(4) + skills.getLevelForXp(5) + skills.getLevelForXp(6) + skills.getLevelForXp(7) + skills.getLevelForXp(8) + skills.getLevelForXp(9) + skills.getLevelForXp(10) + skills.getLevelForXp(11) + skills.getLevelForXp(12) + skills.getLevelForXp(13) + skills.getLevelForXp(14) + skills.getLevelForXp(15) + skills.getLevelForXp(16) + skills.getLevelForXp(17) + skills.getLevelForXp(18) + skills.getLevelForXp(19) + skills.getLevelForXp(20))+","+((skills.getXp(0)) + (skills.getXp(1)) + (skills.getXp(2)) + (skills.getXp(3)) + (skills.getXp(4)) + (skills.getXp(5)) + (skills.getXp(6)) + (skills.getXp(7)) + (skills.getXp(8)) + (skills.getXp(9)) + (skills.getXp(10)) + (skills.getXp(11)) + (skills.getXp(12)) + (skills.getXp(13)) + (skills.getXp(14)) + (skills.getXp(15)) + (skills.getXp(16)) + (skills.getXp(17)) + (skills.getXp(18)) + (skills.getXp(19)) + (skills.getXp(20)))+");");
  71.             destroyConnection();
  72.         } catch (Exception e) {
  73.             return false;
  74.         }
  75.         return true;
  76.     }
  77.  
  78.     public static void restore(Player player) throws SQLException  {
  79.         createConnection();
  80.         Statement statement = con.createStatement();
  81.         String query = "SELECT * FROM skills WHERE playerName = '" + player.getDisplayName() + "'";
  82.         ResultSet results = statement.executeQuery(query);
  83.         if (results.next()) {
  84.             for(int i = 0; i < Skills.SKILL_COUNT; i++) {
  85.                 //int level = (int) results.getDouble(Skills.SKILL_NAME[i] +"lvl");
  86.                 //int xp = (int) results.getDouble(Skills.SKILL_NAME[i] +"xp");
  87.             }
  88.         }
  89.         destroyConnection();
  90.     }
  91.  
  92.     public static int[] getOverall(Player player) {
  93.         int totalLevel = 0;
  94.         int totalXp = 0;
  95.         for(int i = 0; i < Skills.SKILL_COUNT; i++) {
  96.             totalLevel += player.getSkills().getLevelForXp(i);
  97.         }
  98.         for(int i = 0; i < Skills.SKILL_COUNT; i++) {
  99.             totalXp += player.getSkills().getXp(i);
  100.         }
  101.         return new int[] {totalLevel, totalXp};
  102.     }
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top