Guest User

Untitled

a guest
Jul 4th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. package engine.util;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import java.util.Iterator;
  10. import game.Client;
  11.  
  12. public class SQL
  13. {
  14. public static Connection con = null;
  15. public static Statement stmt;
  16. public static boolean printed = false;
  17.  
  18. public static boolean isConnected = false;
  19. private static Iterator e;
  20.  
  21. public static boolean createConnection()
  22. {
  23. try
  24. {
  25. Class.forName("com.mysql.jdbc.Driver").newInstance();
  26. con = DriverManager.getConnection(
  27. "jdbc:mysql://184.22.222.172/taintedx_points", "taintedx_points", "hurrdurr");
  28. stmt = con.createStatement();
  29. isConnected = true;
  30. return true;
  31. } catch (Exception e) {
  32. e.printStackTrace();
  33. isConnected = false;
  34. }return false;
  35. }
  36.  
  37. public static ResultSet query(String s) throws SQLException
  38. {
  39. try
  40. {
  41. stmt = con.createStatement();
  42. if (s.toLowerCase().startsWith("select")) {
  43. ResultSet rs = stmt.executeQuery(s);
  44. return rs;
  45. }
  46. stmt.executeUpdate(s);
  47.  
  48. return null;
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. destroyConnection();
  52. createConnection();
  53. }
  54.  
  55. return null;
  56. }
  57.  
  58. public static void sendDonatePoints(Client c) {
  59. c.sendMessage(" You now have "+ c.donatorpoints +" Donator Points");
  60. }
  61.  
  62. public static void destroyConnection() {
  63. try {
  64. stmt.close();
  65. con.close();
  66. }
  67. catch (Exception localException)
  68. {
  69. }
  70. }
  71.  
  72. public static void processSQL(Client c) {
  73. if (System.currentTimeMillis() - c.lastSQL < 10000L) {
  74. return;
  75. }
  76. c.lastSQL = System.currentTimeMillis();
  77. try {
  78. if (!createConnection()) {
  79. c.sendMessage("Your request could not be processed. Try again later.");
  80. return;
  81. }
  82. ResultSet rs = query("SELECT * FROM donator WHERE finished=false AND name='" + c.playerName.toLowerCase() + "'");
  83. if (rs == null) {
  84. c.sendMessage("You have not ordered any points!");
  85. return;
  86. }
  87. int amount = 0;
  88. ArrayList rows = new ArrayList();
  89. while (rs.next()) {
  90. String s = rs.getString("amount");
  91. try {
  92. int a = (int)(Double.parseDouble(s) * 100.0D);
  93. amount += a;
  94. int row = Integer.parseInt(rs.getString("row"));
  95. rows.add(Integer.valueOf(row));
  96. } catch (Exception e) {
  97. e.printStackTrace();
  98. }
  99. }
  100.  
  101. for (e = rows.iterator(); e.hasNext(); ) { int x = ((Integer)e.next()).intValue();
  102. query("UPDATE donator SET finished=true WHERE row=" + x);
  103. }
  104.  
  105. if (amount <= 0) {
  106. c.sendMessage("You have not ordered any points!");
  107. } else {
  108. c.donatorpoints += amount;
  109. c.donatorbought += amount;
  110. if (c.donatorbought >= 15)
  111. c.status = 1;
  112. if (c.donatorbought >= 100)
  113. c.status = 2;
  114. c.sendMessage("You have claim " + amount + " donator points.");
  115. sendDonatePoints(c);
  116. }
  117. } catch (Exception e) {
  118. e.printStackTrace();
  119. }
  120. }
Add Comment
Please, Sign In to add comment