Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. public class MySQL
  2. {
  3. public static boolean playerExists(String uuid)
  4. {
  5. try
  6. {
  7. ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  8. if (rs.next()) {
  9. return rs.getString("UUID") != null;
  10. }
  11. return false;
  12. }
  13. catch (SQLException e)
  14. {
  15. e.printStackTrace();
  16. }
  17. return false;
  18. }
  19.  
  20. public static void createPlayer(String uuid, String name)
  21. {
  22. if (!playerExists(uuid)) {
  23. MySQLConnector.update("INSERT INTO Stats(UUID, NAME, KILLS, DEATHS, POINTS) VALUES ('" + uuid + "', '" + name + "', '0', '0', '0')");
  24. }
  25. }
  26.  
  27. public static void setName(String uuid, String name)
  28. {
  29. if (playerExists(uuid))
  30. {
  31. MySQLConnector.update("UPDATE Stats SET NAME= '" + name + "' WHERE UUID= '" + uuid + "';");
  32. }
  33. else
  34. {
  35. createPlayer(uuid, name);
  36. setName(uuid, name);
  37. }
  38. }
  39.  
  40. public static Integer getKills(String uuid, String name)
  41. {
  42. Integer i = Integer.valueOf(0);
  43. if (playerExists(uuid))
  44. {
  45. try
  46. {
  47. ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  48. if ((rs.next()) && (Integer.valueOf(rs.getInt("KILLS")) == null)) {}
  49. i = Integer.valueOf(rs.getInt("KILLS"));
  50. }
  51. catch (SQLException e)
  52. {
  53. e.printStackTrace();
  54. }
  55. }
  56. else
  57. {
  58. createPlayer(uuid, name);
  59. getKills(uuid, name);
  60. }
  61. return i;
  62. }
  63.  
  64. public static Integer getDeaths(String uuid, String name)
  65. {
  66. Integer i = Integer.valueOf(0);
  67. if (playerExists(uuid))
  68. {
  69. try
  70. {
  71. ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  72. if ((rs.next()) && (Integer.valueOf(rs.getInt("DEATHS")) == null)) {}
  73. i = Integer.valueOf(rs.getInt("DEATHS"));
  74. }
  75. catch (SQLException e)
  76. {
  77. e.printStackTrace();
  78. }
  79. }
  80. else
  81. {
  82. createPlayer(uuid, name);
  83. getDeaths(uuid, name);
  84. }
  85. return i;
  86. }
  87.  
  88. public static void setKills(String uuid, String name, Integer kills)
  89. {
  90. if (playerExists(uuid))
  91. {
  92. MySQLConnector.update("UPDATE Stats SET KILLS= '" + kills + "' WHERE UUID= '" + uuid + "';");
  93. }
  94. else
  95. {
  96. createPlayer(uuid, name);
  97. setKills(uuid, name, kills);
  98. }
  99. }
  100.  
  101. public static void setDeaths(String uuid, String name, Integer deaths)
  102. {
  103. if (playerExists(uuid))
  104. {
  105. MySQLConnector.update("UPDATE Stats SET DEATHS= '" + deaths + "' WHERE UUID= '" + uuid + "';");
  106. }
  107. else
  108. {
  109. createPlayer(uuid, name);
  110. setDeaths(uuid, name, deaths);
  111. }
  112. }
  113.  
  114. public static Integer getRanking(String p)
  115. {
  116. boolean done = false;
  117. int i = 0;
  118. try
  119. {
  120. ResultSet rs = MySQLConnector.query("SELECT UUID FROM Stats ORDER BY POINTS DESC;");
  121. while ((rs.next()) && (!done))
  122. {
  123. i++;
  124. if (rs.getString(1).equalsIgnoreCase(p)) {
  125. done = true;
  126. }
  127. }
  128. rs.close();
  129. }
  130. catch (SQLException e)
  131. {
  132. System.out.println("Ranking Fehler");
  133. }
  134. return Integer.valueOf(i);
  135. }
  136.  
  137. public static void addKills(String uuid, String name, Integer kills)
  138. {
  139. if (playerExists(uuid))
  140. {
  141. setKills(uuid, name, Integer.valueOf(getKills(uuid, name).intValue() + kills.intValue()));
  142. }
  143. else
  144. {
  145. createPlayer(uuid, name);
  146. addKills(uuid, name, kills);
  147. }
  148. }
  149.  
  150. public static void addDeaths(String uuid, String name, Integer deaths)
  151. {
  152. if (playerExists(uuid))
  153. {
  154. setDeaths(uuid, name, Integer.valueOf(getDeaths(uuid, name).intValue() + deaths.intValue()));
  155. }
  156. else
  157. {
  158. createPlayer(uuid, name);
  159. addDeaths(uuid, name, deaths);
  160. }
  161. }
  162.  
  163. public static void setPoints(String uuid, String name, Integer points)
  164. {
  165. if (playerExists(uuid))
  166. {
  167. MySQLConnector.update("UPDATE Stats SET POINTS= '" + points + "' WHERE UUID= '" + uuid + "';");
  168. }
  169. else
  170. {
  171. createPlayer(uuid, name);
  172. setPoints(uuid, name, points);
  173. }
  174. }
  175.  
  176. public static void addPoints(String uuid, String name, Integer points)
  177. {
  178. if (playerExists(uuid))
  179. {
  180. setPoints(uuid, name, Integer.valueOf(getPoints(uuid, name).intValue() + points.intValue()));
  181. }
  182. else
  183. {
  184. createPlayer(uuid, name);
  185. addPoints(uuid, name, points);
  186. }
  187. }
  188.  
  189. public static Integer getPoints(String uuid, String name)
  190. {
  191. Integer i = Integer.valueOf(0);
  192. if (playerExists(uuid))
  193. {
  194. try
  195. {
  196. ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  197. if ((rs.next()) && (Integer.valueOf(rs.getInt("POINTS")) == null)) {}
  198. i = Integer.valueOf(rs.getInt("POINTS"));
  199. }
  200. catch (SQLException e)
  201. {
  202. e.printStackTrace();
  203. }
  204. }
  205. else
  206. {
  207. createPlayer(uuid, name);
  208. getPoints(uuid, name);
  209. }
  210. return i;
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement