Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.runelive.net.mysql.impl;
- import com.runelive.GameServer;
- import com.runelive.model.StaffRights;
- import com.runelive.model.Skill;
- import com.runelive.net.mysql.SQLCallback;
- import com.runelive.world.content.skill.SkillManager;
- import com.runelive.world.entity.impl.player.Player;
- import java.sql.*;
- /**
- * "The digital revolution is far more significant than the invention of writing or even of printing." - Douglas
- * Engelbart
- * Created on 7/18/2016.
- *
- * @author Seba
- */
- public class Hiscores implements Runnable {
- public static final String HOST = "http://www.district-x.net"; // website ip address
- public static final String USER = "distr759_huser";
- public static final String PASS = "DistrictX";
- public static final String DATABASE = "distr759_highscores";
- public static final String TABLE = "hs_users";
- private Player player;
- private Connection conn;
- private Statement stmt;
- public Hiscores(Player player) {
- this.player = player;
- }
- public boolean connect(String host, String database, String user, String pass) {
- try {
- this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
- return true;
- } catch (SQLException e) {
- e.printStackTrace();
- return false;
- }
- }
- @Override
- public void run() {
- try {
- if (!connect(HOST, DATABASE, USER, PASS)) {
- return;
- }
- String name = player.getUsername();
- PreparedStatement stmt1 = prepare("DELETE FROM "+TABLE+" WHERE username=?");
- stmt1.setString(1, player.getUsername());
- stmt1.execute();
- PreparedStatement stmt2 = prepare(generateQuery());
- stmt2.setString(1, player.getUsername());
- stmt2.setInt(2, player.getStaffRights().ordinal());
- stmt2.setLong(3, player.getSkillManager().getTotalExp());
- for (int i = 4; i <= 28; i++)
- stmt2.setInt(i, player.getSkillManager().getExperience(Skill.forId(i - 4)));
- destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public PreparedStatement prepare(String query) throws SQLException {
- return conn.prepareStatement(query);
- }
- public void destroy() {
- try {
- conn.close();
- conn = null;
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static String generateQuery() {
- StringBuilder sb = new StringBuilder();
- sb.append("INSERT INTO hs_users (");
- sb.append("username, ");
- sb.append("rights, ");
- sb.append("overall_xp, ");
- sb.append("attack_xp, ");
- sb.append("defence_xp, ");
- sb.append("strength_xp, ");
- sb.append("constitution_xp, ");
- sb.append("ranged_xp, ");
- sb.append("prayer_xp, ");
- sb.append("magic_xp, ");
- sb.append("cooking_xp, ");
- sb.append("woodcutting_xp, ");
- sb.append("fletching_xp, ");
- sb.append("fishing_xp, ");
- sb.append("firemaking_xp, ");
- sb.append("crafting_xp, ");
- sb.append("smithing_xp, ");
- sb.append("mining_xp, ");
- sb.append("herblore_xp, ");
- sb.append("agility_xp, ");
- sb.append("thieving_xp, ");
- sb.append("slayer_xp, ");
- sb.append("farming_xp, ");
- sb.append("runecrafting_xp, ");
- sb.append("hunter_xp, ");
- sb.append("construction_xp, ");
- sb.append("summoning_xp, ");
- sb.append("dungeoneering_xp) ");
- sb.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement