Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DavidScape.io;
- import java.sql.*;
- import java.security.MessageDigest;
- import java.util.*;
- import java.lang.*;
- import DavidScape.Server;
- import DavidScape.Engine;
- import DavidScape.io.*;
- import DavidScape.players.Player;
- import DavidScape.util.Misc;
- import java.util.Calendar;
- import java.text.SimpleDateFormat;
- public class SQL {
- public static Connection con = null;
- public static Statement stmt;
- public static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String IP="localhost";
- String DB="highscores";
- String User="root";
- String Pass="jasper15";
- con = DriverManager.getConnection("jdbc:mysql://"+IP+"/"+DB, User, Pass);
- stmt = con.createStatement();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static ResultSet query(String s) throws SQLException {
- try {
- if (s.toLowerCase().startsWith("select")) {
- ResultSet rs = stmt.executeQuery(s);
- Misc.println("Success");
- return rs;
- } else {
- stmt.executeUpdate(s);
- }
- return null;
- } catch (Exception e) {
- destroyConnection();
- createConnection();
- Misc.println("Failed");
- e.printStackTrace();
- }
- return null;
- }
- public static void destroyConnection() {
- try {
- stmt.close();
- con.close();
- } catch (Exception e) {
- //e.printStackTrace();
- }
- }
- public static String now(String dateFormat) {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
- return sdf.format(cal.getTime());
- }
- public static void numOnline() {
- int i = 0;
- for(Player p : Engine.players) {
- if(p != null) {
- i++;
- }
- }
- try {
- query("TRUNCATE TABLE `numonline`");
- query("TRUNCATE TABLE `currentonline`");
- query("INSERT INTO `numonline` (`online`) VALUES (" + i + ");");
- for(Player p: Engine.players) {
- if(p != null) {
- query("INSERT INTO `currentonline` (`username`) VALUES ('"+p.username+"');");
- }
- }
- } catch(Exception e) {e.printStackTrace();}
- }
- public static boolean saveHighScore(Player p) {
- try {
- String timeF = "HH:mm";
- String dateF = "EEE, MMM dd, yyyy";
- query("DELETE FROM `skills` WHERE playerName = '"+p.username+"';");
- query("DELETE FROM `skillsoverall` WHERE playerName = '"+p.username+"';");
- query("DELETE FROM `lastlogin` WHERE playerName = '"+p.username+"';");
- 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 ('"+p.username+"',"+p.skillLvl[0]+","+p.skillXP[0]+","+p.skillLvl[1]+","+p.skillXP[1]+","+p.skillLvl[2]+","+p.skillXP[2]+","+p.skillLvl[3]+","+p.skillXP[3]+","+p.skillLvl[4]+","+p.skillXP[4]+","+p.skillLvl[5]+","+p.skillXP[5]+","+p.skillLvl[6]+","+p.skillXP[6]+","+p.skillLvl[7]+","+p.skillXP[7]+","+p.skillLvl[8]+","+p.skillXP[8]+","+p.skillLvl[9]+","+p.skillXP[9]+","+p.skillLvl[10]+","+p.skillXP[10]+","+p.skillLvl[11]+","+p.skillXP[11]+","+p.skillLvl[12]+","+p.skillXP[12]+","+p.skillLvl[13]+","+p.skillXP[13]+","+p.skillLvl[14]+","+p.skillXP[14]+","+p.skillLvl[15]+","+p.skillXP[15]+","+p.skillLvl[16]+","+p.skillXP[16]+","+p.skillLvl[17]+","+p.skillXP[17]+","+p.skillLvl[18]+","+p.skillXP[18]+","+p.skillLvl[19]+","+p.skillXP[19]+","+p.skillLvl[20]+","+p.skillXP[20]+","+p.skillLvl[21]+","+p.skillXP[21]+","+p.skillLvl[22]+","+p.skillXP[22]+","+p.skillLvl[23]+","+p.skillXP[23]+");");
- query("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('"+p.username+"',"+(p.skillLvl[0] + p.skillLvl[1] + p.skillLvl[2] + p.skillLvl[3] + p.skillLvl[4] + p.skillLvl[5] + p.skillLvl[6] + p.skillLvl[7] + p.skillLvl[8] + p.skillLvl[9] + p.skillLvl[10] + p.skillLvl[11] + p.skillLvl[12] + p.skillLvl[13] + p.skillLvl[14] + p.skillLvl[15] + p.skillLvl[16] + p.skillLvl[17] + p.skillLvl[18] + p.skillLvl[19] + p.skillLvl[20] + p.skillLvl[21] + p.skillLvl[22] + p.skillLvl[23])+","+((p.skillXP[0]) + (p.skillXP[1]) + (p.skillXP[2]) + (p.skillXP[3]) + (p.skillXP[4]) + (p.skillXP[5]) + (p.skillXP[6]) + (p.skillXP[7]) + (p.skillXP[8]) + (p.skillXP[9]) + (p.skillXP[10]) + (p.skillXP[11]) + (p.skillXP[12]) + (p.skillXP[13]) + (p.skillXP[14]) + (p.skillXP[15]) + (p.skillXP[16]) + (p.skillXP[17]) + (p.skillXP[18]) + (p.skillXP[19]) + (p.skillXP[20]) + (p.skillXP[21]) + (p.skillXP[22]) + (p.skillXP[23]))+");");
- query("INSERT INTO `lastlogin` (`playerName`,`time`,`date` ) VALUES ('"+p.username+"','"+now(timeF)+"','"+now(dateF)+"');");
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement