Guest User

Untitled

a guest
Jun 11th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. package server.util;
  2.  
  3. import server.model.players.packets.Commands;
  4. import java.sql.*;
  5. import server.model.players.Client;
  6.  
  7. public class MadTurnipConnection extends Thread {
  8.  
  9. public static Connection con = null;
  10. public static Statement stm;
  11.  
  12. public static void createConnection() {
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver").newInstance();
  15. con = DriverManager.getConnection("jdbc:mysql://176.31.159.232/sedexrsp_donate", "sedexrsp_admin", "a123456");
  16. stm = con.createStatement();
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. con = null;
  20. stm = null;
  21. }
  22. }
  23.  
  24. public MadTurnipConnection(){
  25.  
  26. }
  27.  
  28. public void run() {
  29. while(true) {
  30. try {
  31. if(con == null)
  32. createConnection();
  33. else
  34. ping();
  35. Thread.sleep(10000);//10 seconds
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41.  
  42. public static void ping(){
  43. try {
  44. String query = "SELECT * FROM donation WHERE username = 'null'";
  45. query(query);
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. con = null;
  49. stm = null;
  50. }
  51. }
  52.  
  53. public static void addDonateItems(final Client c,final String name){
  54. if(con == null){
  55. if(stm != null){
  56. try {
  57. stm = con.createStatement();
  58. } catch(Exception e){
  59. con = null;
  60. stm = null;
  61. //put a sendmessage here telling them to relog in 30 seconds
  62. return;
  63. }
  64. } else {
  65. //put a sendmessage here telling them to relog in 30 seconds
  66. return;
  67. }
  68. }
  69. new Thread(){
  70. @Override
  71. public void run()
  72. {
  73. try {
  74. String name2 = name.replaceAll(" ","_");
  75. String query = "SELECT * FROM donation WHERE username = '"+name2+"'";
  76. ResultSet rs = query(query);
  77. boolean b = false;
  78. while(rs.next()){
  79. int prod = Integer.parseInt(rs.getString("productid"));
  80. int price = Integer.parseInt(rs.getString("price"));
  81. if(prod == 1 && price == 3){
  82. c.getItems().addItem(14094,1);
  83. c.getItems().addItem(14095,1);
  84. c.getItems().addItem(14096,1);
  85. b = true;
  86. } else if(prod == 2 && price == 3){
  87. c.getItems().addItem(14490,1);
  88. c.getItems().addItem(14492,1);
  89. c.getItems().addItem(14494,1);
  90. b = true;
  91. } else if(prod == 3 && price == 3){
  92. c.getItems().addItem(19780,1);
  93. b = true;
  94. } else if(prod == 4 && price == 1){
  95. c.getItems().addItem(15486,1);
  96. b = true;
  97. } else if(prod == 5 && price == 1){
  98. c.getItems().addItem(6818,1);
  99. b = true;
  100. } else if(prod == 6 && price == 1){
  101. c.getItems().addItem(16933,1);
  102. b = true;
  103. } else if(prod == 7 && price == 1){
  104. c.getItems().addItem(13661,1);
  105. b = true;
  106. } else if(prod == 8 && price == 1){
  107. c.getItems().addItem(17279,1);
  108. b = true;
  109. } else if(prod == 9 && price == 5){
  110. c.getItems().addItem(16281,1);
  111. c.getItems().addItem(16347,1);
  112. c.getItems().addItem(16391,1);
  113. c.getItems().addItem(16677,1);
  114. c.getItems().addItem(16699,1);
  115. c.getItems().addItem(17247,1);
  116. c.getItems().addItem(17349,1);
  117. b = true;
  118. } else if(prod == 10 && price == 4){
  119. c.isDonator += 1;
  120. b = true;
  121. }
  122. }
  123. if(b){
  124. query("DELETE FROM `donation` WHERE `username` = '"+name2+"';");
  125. }
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. con = null;
  129. stm = null;
  130. }
  131. }
  132. }.start();
  133. }
  134.  
  135. public static ResultSet query(String s) throws SQLException {
  136. try {
  137. if (s.toLowerCase().startsWith("select")) {
  138. ResultSet rs = stm.executeQuery(s);
  139. return rs;
  140. } else {
  141. stm.executeUpdate(s);
  142. }
  143. return null;
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. con = null;
  147. stm = null;
  148. }
  149. return null;
  150. }
  151. }
Add Comment
Please, Sign In to add comment