Guest User

Untitled

a guest
May 31st, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. package server.util;
  2.  
  3. import java.sql.*;
  4. import server.model.players.Client;
  5.  
  6. public class Edy extends Thread {
  7.  
  8. private static String url = "jdbc:mysql://quantumx-rsps.com/teemu_mybb";
  9. private static String user = "teemu_server";
  10. private static String pass = "lotto9469";//the pass u just entered
  11. public static Connection con = null;
  12. public static Statement stm;
  13.  
  14. public static void createConnection() {
  15. try {
  16. Class.forName("com.mysql.jdbc.Driver").newInstance();
  17. con = DriverManager.getConnection(url, user, pass);
  18. stm = con.createStatement();
  19. } catch (Exception e) {
  20. e.printStackTrace();
  21. con = null;
  22. stm = null;
  23. }
  24. }
  25.  
  26. public Edy() {
  27.  
  28. }
  29.  
  30. public void run() {
  31. while(true) {
  32. try {
  33. if(con == null)
  34. createConnection();
  35. else
  36. ping();
  37. Thread.sleep(10000);//10 seconds
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43.  
  44. public static void ping(){
  45. try {
  46. String query = "SELECT * FROM donation WHERE Username = 'null'";
  47. ResultSet rs = stm.executeQuery(query);
  48. rs.close();
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. con = null;
  52. stm = null;
  53. }
  54. }
  55.  
  56. public static void giveDonor(final Client c) {
  57. if(con == null){
  58. if(stm != null){
  59. try {
  60. stm = con.createStatement();
  61. } catch(Exception e){
  62. con = null;
  63. stm = null;
  64. c.sendMessage("An error occured while trying to make you a donor");
  65. c.sendMessage("please try again in 1 minute.");
  66. return;
  67. }
  68. } else {
  69. c.sendMessage("An error occured while trying to make you a donor");
  70. c.sendMessage("please try again in 1 minute.");
  71. return;
  72. }
  73. }
  74. new Thread(){
  75. @Override
  76. public void run()
  77. {
  78. try {
  79. stm.executeUpdate("UPDATE `mybb_users` SET additionalgroups='8' WHERE username LIKE '"+c.playerName+"'");
  80. c.playerRights = 4;
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. con = null;
  84. stm = null;
  85. }
  86. }
  87. }.start();
  88. }
  89. public static void handleVoted(final Client c) {
  90. if(con == null){
  91. if(stm != null){
  92. try {
  93. stm = con.createStatement();
  94. } catch(Exception e){
  95. con = null;
  96. stm = null;
  97. c.sendMessage("an error occured while trying to claim your vote reward");
  98. c.sendMessage("please try again in 1 minute.");
  99. return;
  100. }
  101. } else {
  102. c.sendMessage("an error occured while trying to claim your vote reward");
  103. c.sendMessage("please try again in 1 minute.");
  104. return;
  105. }
  106. }
  107. new Thread(){
  108. @Override
  109. public void run()
  110. {
  111. try {
  112. stm.executeQuery("SELECT * FROM votes WHERE playerName LIKE '"+c.playerName+"' AND taken='0'");
  113. ResultSet results = stm.getResultSet();
  114. if(results.next()) {
  115. if (rewardVoter(c, false)) {
  116. stm.executeUpdate("UPDATE `votes` SET taken='1' WHERE playerName LIKE '"+c.playerName+"'");
  117. rewardVoter(c, true);
  118. c.sendMessage("Thank you for voting to QuantumX! Vote again every day!.");
  119. } else {
  120. c.sendMessage("You don't have enough free space in your inventory.");
  121. c.sendMessage("Try again when you do.");
  122. }
  123. } else {
  124. c.sendMessage("You didn't ::vote, please vote then try again.");
  125. }
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. con = null;
  129. stm = null;
  130. }
  131. }
  132. }.start();
  133. }
  134. public static boolean rewardVoter(Client c, boolean give) {
  135. if (give) {
  136. //reward voters with 20 pkp
  137. c.pkp += 20;
  138. }
  139. return true;
  140. }
  141. public static void handleDonated(final Client c) {
  142. if(con == null){
  143. if(stm != null){
  144. try {
  145. stm = con.createStatement();
  146. } catch(Exception e){
  147. con = null;
  148. stm = null;
  149. c.sendMessage("an error occured while trying to check your donation");
  150. c.sendMessage("please try again in 1 minute.");
  151. //e.printStackTrace();
  152. return;
  153. }
  154. } else {
  155. c.sendMessage("an error occured while trying to check your donation");
  156. c.sendMessage("please try again in 1 minute.");
  157. return;
  158. }
  159. }
  160. new Thread(){
  161. @Override
  162. public void run()
  163. {
  164. try {
  165. stm.executeQuery("SELECT * FROM donation WHERE username LIKE '"+c.playerName+"' AND Taken='0'");
  166. ResultSet results = stm.getResultSet();
  167. if(results.next()) {
  168. int ID = results.getInt("ID");
  169. int Package = results.getInt("Package");
  170. if (rewardDonator(c, Package, false)) {
  171. stm.executeUpdate("UPDATE `donation` SET Taken='1' WHERE ID='" + ID + "'");
  172. rewardDonator(c, Package, true);
  173. c.sendMessage("Thank you very much for your donation to QuantumX.");
  174. } else {
  175. c.sendMessage("You don't have enough free space in your inventory.");
  176. c.sendMessage("Try again when you do.");
  177. }
  178. } else {
  179. c.sendMessage("You didn't donate, please donate then try again.");
  180. c.sendMessage("Type ::donate to check the store out!");
  181. }
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. con = null;
  185. stm = null;
  186. }
  187. }
  188. }.start();
  189. }
  190.  
  191. public static boolean rewardDonator(Client c, int pack, boolean give) {
  192. switch (pack) {
  193.  
  194. /* Donor Rank*/
  195. case 5: //Case is the number of the package for the item. For example we have whip with package 5 so we do case 5
  196. //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  197. if (give) {
  198. //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  199. giveDonor(c);
  200. }
  201. //} else {
  202. //return false;
  203. //}
  204. break;
  205. case 10:
  206. //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  207. if (give) {
  208. //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  209. c.pkp += 100;
  210. }
  211. //} else {
  212. //return false;
  213. //}
  214. break;
  215. case 20:
  216. //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  217. if (give) {
  218. //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  219. c.pkp += 200;
  220. }
  221. //} else {
  222. //return false;
  223. //}
  224. break;
  225. case 30:
  226. //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  227. if (give) {
  228. //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  229. c.pkp += 500;
  230. }
  231. //} else {
  232. //return false;
  233. //}
  234. break;
  235. case 40:
  236. if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  237. if (give) {
  238. c.getItems().addItem(20135, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  239. c.getItems().addItem(20139, 1);
  240. c.getItems().addItem(20143, 1);
  241. }
  242. } else {
  243. return false;
  244. }
  245. break;
  246. case 50:
  247. if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  248. if (give) {
  249. c.getItems().addItem(20159, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  250. c.getItems().addItem(20163, 1);
  251. c.getItems().addItem(20167, 1);
  252. }
  253. } else {
  254. return false;
  255. }
  256. break;
  257. case 60:
  258. if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
  259. if (give) {
  260. c.getItems().addItem(20147, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
  261. c.getItems().addItem(20151, 1);
  262. c.getItems().addItem(20155, 1);
  263. }
  264. } else {
  265. return false;
  266. }
  267. break;
  268. default:
  269.  
  270. break;
  271.  
  272. }
  273. return true;
  274. }
  275. }
Add Comment
Please, Sign In to add comment