Advertisement
Guest User

Untitled

a guest
May 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. package com.runelive.net.mysql.impl;
  2.  
  3. import com.runelive.GameServer;
  4. import com.runelive.model.StaffRights;
  5. import com.runelive.model.Skill;
  6. import com.runelive.net.mysql.SQLCallback;
  7. import com.runelive.world.content.skill.SkillManager;
  8. import com.runelive.world.entity.impl.player.Player;
  9.  
  10. import java.sql.*;
  11.  
  12.  
  13. /**
  14. * "The digital revolution is far more significant than the invention of writing or even of printing." - Douglas
  15. * Engelbart
  16. * Created on 7/18/2016.
  17. *
  18. * @author Seba
  19. */
  20. public class Hiscores implements Runnable {
  21.  
  22. public static final String HOST = "http://www.district-x.net"; // website ip address
  23. public static final String USER = "distr759_huser";
  24. public static final String PASS = "DistrictX";
  25. public static final String DATABASE = "distr759_highscores";
  26. public static final String TABLE = "hs_users";
  27.  
  28. private Player player;
  29. private Connection conn;
  30. private Statement stmt;
  31.  
  32. public Hiscores(Player player) {
  33. this.player = player;
  34. }
  35.  
  36. public boolean connect(String host, String database, String user, String pass) {
  37. try {
  38. this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
  39. return true;
  40. } catch (SQLException e) {
  41. e.printStackTrace();
  42. return false;
  43. }
  44. }
  45.  
  46. @Override
  47. public void run() {
  48. try {
  49. if (!connect(HOST, DATABASE, USER, PASS)) {
  50. return;
  51. }
  52. String name = player.getUsername();
  53.  
  54. PreparedStatement stmt1 = prepare("DELETE FROM "+TABLE+" WHERE username=?");
  55. stmt1.setString(1, player.getUsername());
  56. stmt1.execute();
  57.  
  58. PreparedStatement stmt2 = prepare(generateQuery());
  59. stmt2.setString(1, player.getUsername());
  60. stmt2.setInt(2, player.getStaffRights().ordinal());
  61. stmt2.setLong(3, player.getSkillManager().getTotalExp());
  62. for (int i = 4; i <= 28; i++)
  63. stmt2.setInt(i, player.getSkillManager().getExperience(Skill.forId(i - 4)));
  64. destroy();
  65. } catch (Exception e) {
  66. e.printStackTrace();
  67. }
  68. }
  69.  
  70. public PreparedStatement prepare(String query) throws SQLException {
  71. return conn.prepareStatement(query);
  72. }
  73.  
  74. public void destroy() {
  75. try {
  76. conn.close();
  77. conn = null;
  78. if (stmt != null) {
  79. stmt.close();
  80. stmt = null;
  81. }
  82. } catch(Exception e) {
  83. e.printStackTrace();
  84. }
  85. }
  86.  
  87. public static String generateQuery() {
  88. StringBuilder sb = new StringBuilder();
  89. sb.append("INSERT INTO hs_users (");
  90. sb.append("username, ");
  91. sb.append("rights, ");
  92. sb.append("overall_xp, ");
  93. sb.append("attack_xp, ");
  94. sb.append("defence_xp, ");
  95. sb.append("strength_xp, ");
  96. sb.append("constitution_xp, ");
  97. sb.append("ranged_xp, ");
  98. sb.append("prayer_xp, ");
  99. sb.append("magic_xp, ");
  100. sb.append("cooking_xp, ");
  101. sb.append("woodcutting_xp, ");
  102. sb.append("fletching_xp, ");
  103. sb.append("fishing_xp, ");
  104. sb.append("firemaking_xp, ");
  105. sb.append("crafting_xp, ");
  106. sb.append("smithing_xp, ");
  107. sb.append("mining_xp, ");
  108. sb.append("herblore_xp, ");
  109. sb.append("agility_xp, ");
  110. sb.append("thieving_xp, ");
  111. sb.append("slayer_xp, ");
  112. sb.append("farming_xp, ");
  113. sb.append("runecrafting_xp, ");
  114. sb.append("hunter_xp, ");
  115. sb.append("construction_xp, ");
  116. sb.append("summoning_xp, ");
  117. sb.append("dungeoneering_xp) ");
  118. sb.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  119. return sb.toString();
  120. }
  121.  
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement