Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. package server.util;
  2.  
  3. import java.sql.*;
  4. import server.model.players.Client;
  5.  
  6. public class SabsabiDonor extends Thread {
  7.  
  8. public static Connection con = null;
  9. public static Statement stm;
  10.  
  11.  
  12. public static void createConnection() {
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver").newInstance();
  15. con = DriverManager.getConnection("jdbc:mysql://sabsabionline.com/sabsabi_wut", "sabsabi_wut", "passwordson");
  16. stm = con.createStatement();
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. con = null;
  20. stm = null;
  21. }
  22. }
  23.  
  24. public SabsabiDonor(){
  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. }
  49. }
  50.  
  51. public static void addDonateItems(final Client c,final String name){
  52. new Thread(){
  53. @Override
  54. public void run()
  55. {
  56. try {
  57. String name2 = name.replaceAll(" ","_");
  58. String query = "SELECT * FROM donation WHERE username = '"+name2+"'";
  59. ResultSet rs = query(query);
  60. boolean b = false;
  61. while(rs.next()){
  62. b = true;
  63. if(Integer.parseInt(rs.getString("productid")) == 1){
  64. c.getItems().addItem(11694,1);
  65. } else if(Integer.parseInt(rs.getString("productid")) == 2){
  66. c.getItems().addItem(11700,1);
  67. } else if(Integer.parseInt(rs.getString("productid")) == 3){
  68. c.getItems().addItem(995,150000000);
  69. } else if(Integer.parseInt(rs.getString("productid")) == 4){
  70. c.getItems().addItem(1048,1);//white phat
  71. } else if(Integer.parseInt(rs.getString("productid")) == 5){
  72. c.getItems().addItem(1050,1);// santa hat
  73. } else if(Integer.parseInt(rs.getString("productid")) == 6){
  74. c.donorPoints += 500;// 500 donor points
  75. } else if(Integer.parseInt(rs.getString("productid")) == 7){
  76. c.donorPoints += 1000;// 1000 donor points
  77. } else if(Integer.parseInt(rs.getString("productid")) == 8){
  78. c.donorPoints += 1500;// 1500 donor points
  79. } else if(Integer.parseInt(rs.getString("productid")) == 9){
  80. c.donorPoints += 2000;// 2000 donor points
  81. } else if(Integer.parseInt(rs.getString("productid")) == 10){
  82. c.donorPoints += 2500;// 2500 donor points
  83. } else if(Integer.parseInt(rs.getString("productid")) == 11){
  84. c.yellPoints += 100;// 100 yell points
  85. } else if(Integer.parseInt(rs.getString("productid")) == 12){
  86. c.yellPoints += 200;// 200 yell points
  87. } else if(Integer.parseInt(rs.getString("productid")) == 13){
  88. c.yellPoints += 300;// 300 yell points
  89. }
  90. }
  91. if(b){
  92. query("DELETE FROM `donation` WHERE `username` = '"+name2+"';");
  93. }
  94. } catch (Exception e) {
  95. e.printStackTrace();
  96. }
  97. }
  98. }.start();
  99. }
  100.  
  101. public static ResultSet query(String s) throws SQLException {
  102. try {
  103. if (s.toLowerCase().startsWith("select")) {
  104. ResultSet rs = stm.executeQuery(s);
  105. return rs;
  106. } else {
  107. stm.executeUpdate(s);
  108. }
  109. return null;
  110. } catch (Exception e) {
  111. e.printStackTrace();
  112. }
  113. return null;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement