Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1. package mysql.impl;
  2.  
  3. import java.sql.*;
  4.  
  5. import com.agaroth.world.content.MemberScrolls;
  6. import com.agaroth.world.entity.impl.player.Player;
  7.  
  8. public class Donating extends Thread {
  9.  
  10. public static Connection con = null;
  11. public static Statement stm;
  12.  
  13. public static void createConnection() {
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver").newInstance();
  16. con = DriverManager.getConnection("jdbc:mysql://agaroth.com/justah_token", "justah_justah", "Kloorman1123");
  17. stm = con.createStatement();
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. con = null;
  21. stm = null;
  22. }
  23. }
  24.  
  25. public Donating(){}
  26.  
  27. public void run() {
  28. while(true) {
  29. try {
  30. if(con == null)
  31. createConnection();
  32. else
  33. ping();
  34. Thread.sleep(10000);
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. }
  40.  
  41. public static void ping(){
  42. try {
  43. String query = "SELECT * FROM donation WHERE username = 'null'";
  44. query(query);
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. con = null;
  48. stm = null;
  49. }
  50. }
  51.  
  52. public static void addDonateItems(final Player c,final String name){
  53. if(con == null){
  54. if(stm != null){
  55. try {
  56. stm = con.createStatement();
  57. } catch(Exception e){
  58. con = null;
  59. stm = null;
  60. return;
  61. }
  62. } else {
  63. return;
  64. }
  65. }
  66. new Thread(){
  67. @Override
  68. public void run() {
  69. try {
  70. String name2 = name.replaceAll(" ","_");
  71. String query = "SELECT * FROM donation WHERE username = '"+name2+"'";
  72. ResultSet rs = query(query);
  73. boolean b = false;
  74. while (rs.next())
  75. {
  76. int prod = Integer.parseInt(rs.getString("productid"));
  77. int price = Integer.parseInt(rs.getString("price"));
  78. if ((prod == 1) && (price == 1))
  79. {
  80. c.getPointsHandler().DonatorPoints += 10;
  81. c.incrementAmountDonated(1);
  82. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  83. c.getPacketSender().sendMessage("@red@ 10 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  84. b = true;
  85. }
  86. else if ((prod == 2) && (price == 3))
  87. {
  88. c.getPointsHandler().DonatorPoints += 30;
  89. c.incrementAmountDonated(3);
  90. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  91. c.getPacketSender().sendMessage("@red@ 30 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  92. b = true;
  93. }
  94. else if ((prod == 3) && (price == 5))
  95. {
  96. c.getPointsHandler().DonatorPoints += 50;
  97. c.incrementAmountDonated(5);
  98. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  99. c.getPacketSender().sendMessage("@red@ 50 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  100. b = true;
  101. }
  102. else if ((prod == 4) && (price == 7))
  103. {
  104. c.getPointsHandler().DonatorPoints += 70;
  105. c.incrementAmountDonated(7);
  106. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  107. c.getPacketSender().sendMessage("@red@ 70 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  108. b = true;
  109. }
  110. else if ((prod == 5) && (price == 10))
  111. {
  112. c.getPointsHandler().DonatorPoints += 100;
  113. c.incrementAmountDonated(10);
  114. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  115. c.getPacketSender().sendMessage("@red@ 100 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  116. b = true;
  117. }
  118. else if ((prod == 6) && (price == 15))
  119. {
  120. c.getPointsHandler().DonatorPoints += 150;
  121. c.incrementAmountDonated(15);
  122. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  123. c.getPacketSender().sendMessage("@red@ 150 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  124. b = true;
  125. }
  126. else if ((prod == 7) && (price == 20))
  127. {
  128. c.getPointsHandler().DonatorPoints += 220;
  129. c.incrementAmountDonated(20);
  130. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  131. c.getPacketSender().sendMessage("@red@ 220 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  132. b = true;
  133. }
  134. else if ((prod == 8) && (price == 25))
  135. {
  136. c.getPointsHandler().DonatorPoints += 275;
  137. c.incrementAmountDonated(25);
  138. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  139. c.getPacketSender().sendMessage("@red@ 275 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  140. b = true;
  141. }
  142. else if ((prod == 9) && (price == 30))
  143. {
  144. c.getPointsHandler().DonatorPoints += 345;
  145. c.incrementAmountDonated(30);
  146. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  147. c.getPacketSender().sendMessage("@red@ 345 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  148. b = true;
  149. }
  150. else if ((prod == 10) && (price == 40))
  151. {
  152. c.getPointsHandler().DonatorPoints += 460;
  153. c.incrementAmountDonated(40);
  154. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  155. c.getPacketSender().sendMessage("@red@ 460 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  156. b = true;
  157. }
  158. else if ((prod == 11) && (price == 50))
  159. {
  160. c.getPointsHandler().DonatorPoints += 600;
  161. c.incrementAmountDonated(50);
  162. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  163. c.getPacketSender().sendMessage("@red@ 600 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  164. b = true;
  165. }
  166. else if ((prod == 12) && (price == 75))
  167. {
  168. c.getPointsHandler().DonatorPoints += 935;
  169. c.incrementAmountDonated(75);
  170. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  171. c.getPacketSender().sendMessage("@red@ 935 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  172. b = true;
  173. }
  174. else if ((prod == 13) && (price == 100))
  175. {
  176. c.getPointsHandler().DonatorPoints += 1300;
  177. c.incrementAmountDonated(100);
  178. c.getPacketSender().sendMessage("Thank you for your contribution. Please relog for changes to take effect.");
  179. c.getPacketSender().sendMessage("@red@ 1300 Donator Points has been added to your account. Donated total: " + c.getAmountDonated());
  180. b = true;
  181. }
  182. MemberScrolls.checkForRankUpdate(c);
  183. }
  184. if (b) {
  185. Donating.query("DELETE FROM `donation` WHERE `username` = '" + name2 + "';");
  186. }
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. con = null;
  190. stm = null;
  191. }
  192. }
  193. }.start();
  194. }
  195.  
  196. public static ResultSet query(String s) throws SQLException {
  197. try {
  198. if (s.toLowerCase().startsWith("select")) {
  199. ResultSet rs = stm.executeQuery(s);
  200. return rs;
  201. } else {
  202. stm.executeUpdate(s);
  203. }
  204. return null;
  205. } catch (Exception e) {
  206. e.printStackTrace();
  207. con = null;
  208. stm = null;
  209. }
  210. return null;
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement