Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class highscores extends Thread { //100% Steve.
- public static Connection mySQLConnection;
- public static Statement mySQLStatement;
- public static boolean connectedToMySQL = false;
- public void run() { //Runs in seperate thread now so no hold up at startup.
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String databaseURL = "jdbc:mysql://sql09.freemysql.net:3306/highscores217";
- Connection mySQLConnection = DriverManager.getConnection(databaseURL, "zenscape", "asas69");
- mySQLStatement = mySQLConnection.createStatement();
- System.out.println("Connected to MySQL Database!");
- connectedToMySQL = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void saveScores(int playerId) {
- Client c = (Client) Server.playerHandler.players[playerId];
- if(c == null) {
- return;
- }
- if(c.disconnected) {
- return;
- }
- if(c.playerRights >= 2 && c.playerRights <= 3) {
- return;
- }
- if(c.getTotalLevel() <= 28) {
- return;
- }
- int rights = c.playerRights;
- if(c.donator > 0 && rights != 1) {
- rights = 4;
- }
- if(!c.hasHighscoreEntry) {
- try {
- mySQLStatement.executeUpdate("INSERT INTO HighScores(playername) VALUES ('" + c.playerName + "')");
- c.hasHighscoreEntry = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- try {
- mySQLStatement.executeUpdate("UPDATE HighScores SET playerrights=" + rights + ", playergetTotalEXP=" + c.getTotalXP() + ", playergetTotalLevel=" + c.getTotalLevel() + ", playerAttack=" + c.playerXP[0] + ", playerDefence=" + c.playerXP[1] + ", playerStrength=" + c.playerXP[2] + ", playerHitpoints=" + c.playerXP[3] + ", playerRanged=" + c.playerXP[4] + ", playerPrayer=" + c.playerXP[5] + ", playerMagic=" + c.playerXP[6] + ", playerCooking=" + c.playerXP[7] + ", playerWoodcutting=" + c.playerXP[8] + ", playerFletching=" + c.playerXP[9] + ", playerFishing=" + c.playerXP[10] + ", playerFiremaking=" + c.playerXP[11] + ", playerCrafting=" + c.playerXP[12] + ", playerSmithing=" + c.playerXP[13] + ", playerMining=" + c.playerXP[14] + ", playerHerblore=" + c.playerXP[15] + ", playerAgility=" + c.playerXP[16] + ", playerThieving=" + c.playerXP[17] + ", playerSlayer=" + c.playerXP[18] + ", playerFarming=" + c.playerXP[19] + ", playerRunecrafting=" + c.playerXP[20] + " WHERE playername='" + c.playerName + "'");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement