Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. package com.arlania;
  2.  
  3. import java.sql.*;
  4.  
  5. import com.arlania.world.entity.impl.player.Player;
  6.  
  7. public class FoxVote implements Runnable {
  8.  
  9. public static final String HOST = "66.85.";
  10. public static final String USER = "runeziuj_";
  11. public static final String PASS = "cKeZo";
  12. public static final String DATABASE = "runeziuj";
  13.  
  14. private Player player;
  15. private Connection conn;
  16. private Statement stmt;
  17.  
  18. public FoxVote(Player player) {
  19. this.player = player;
  20. }
  21.  
  22. @Override
  23. public void run() {
  24. try {
  25. if (!connect(HOST, DATABASE, USER, PASS)) {
  26. return;
  27. }
  28.  
  29. String name = player.getUsername().toLowerCase().replace(" ", "_");
  30. ResultSet rs = executeQuery(
  31. "SELECT * FROM fx_votes WHERE username='" + name + "' AND claimed=0 AND callback_date IS NOT NULL");
  32.  
  33. while (rs.next()) {
  34. String timestamp = rs.getTimestamp("callback_date").toString();
  35. String ipAddress = rs.getString("ip_address");
  36. int siteId = rs.getInt("site_id");
  37.  
  38. player.getInventory().add(19670, 5);
  39. player.getInventory().add(995, 5000000);
  40. player.getPacketSender().sendMessage("<shad=1>@mag@Thanks for voting!");
  41.  
  42. System.out.println("[VOTESYSTEM] Vote claimed by " + name + ". (sid: " + siteId + ", ip: " + ipAddress
  43. + ", time: " + timestamp + ")");
  44.  
  45. rs.updateInt("claimed", 1); // do not delete otherwise they can
  46. // reclaim!
  47. rs.updateRow();
  48. }
  49.  
  50. destroy();
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
  54. }
  55.  
  56. public boolean connect(String host, String database, String user, String pass) {
  57. try {
  58. this.conn = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, user, pass);
  59. return true;
  60. } catch (SQLException e) {
  61. System.out.println("Failing connecting to database!");
  62. return false;
  63. }
  64. }
  65.  
  66. public void destroy() {
  67. try {
  68. conn.close();
  69. conn = null;
  70. if (stmt != null) {
  71. stmt.close();
  72. stmt = null;
  73. }
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. }
  77. }
  78.  
  79. public int executeUpdate(String query) {
  80. try {
  81. this.stmt = this.conn.createStatement(1005, 1008);
  82. int results = stmt.executeUpdate(query);
  83. return results;
  84. } catch (SQLException ex) {
  85. ex.printStackTrace();
  86. }
  87. return -1;
  88. }
  89.  
  90. public ResultSet executeQuery(String query) {
  91. try {
  92. this.stmt = this.conn.createStatement(1005, 1008);
  93. ResultSet results = stmt.executeQuery(query);
  94. return results;
  95. } catch (SQLException ex) {
  96. ex.printStackTrace();
  97. }
  98. return null;
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement