Advertisement
Guest User

SQLStats

a guest
Dec 24th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package me.madebyproxxy.spigot.rc.lobbysystem.coins;
  2.  
  3. import me.madebyproxxy.spigot.rc.lobbysystem.Main;
  4.  
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8.  
  9. public class SQLStats {
  10.  
  11. public static boolean playerExists(String uuid) {
  12. try {
  13. ResultSet rs = Main.getPlugin(Main.class).mySQL2.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  14. if(rs.next()) {
  15. return rs.getString("UUID") != null;
  16. }
  17. return false;
  18. }catch (SQLException e) {
  19. e.printStackTrace();
  20. }
  21.  
  22. return false;
  23. }
  24.  
  25. public static void setupPlayer(String uuid) {
  26. if(!(playerExists(uuid))) {
  27. Main.getPlugin(Main.class).mySQL2.update("INSERT INTO Stats(UUID, COINS) VALUES ('" + uuid + "', '0');");
  28. }
  29. }
  30.  
  31. public static Integer getCoins(String uuid) {
  32. Integer i = 0;
  33.  
  34. if(playerExists(uuid)) {
  35. try {
  36. ResultSet rs = Main.getPlugin(Main.class).mySQL2.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  37. if((rs.next()) || (Integer.valueOf(rs.getInt("COINS")) == null));
  38.  
  39. i = rs.getInt("COINS");
  40. } catch (SQLException e) {
  41. e.printStackTrace();
  42. }
  43. }else {
  44. setupPlayer(uuid);
  45. getCoins(uuid);
  46. }
  47.  
  48. return i;
  49. }
  50.  
  51. public static void setCoins(String uuid, Integer coins) {
  52. if(playerExists(uuid)) {
  53. Main.getPlugin(Main.class).mySQL2.update("UPDATE Stats SET COINS= '" + coins + "' WHERE UUID= '" + uuid + "';");
  54. }else {
  55. setupPlayer(uuid);
  56. setCoins(uuid, coins);
  57. }
  58. }
  59.  
  60. public static void addCoins(String uuid, Integer coins) {
  61. if(playerExists(uuid)) {
  62. setCoins(uuid, Integer.valueOf(getCoins(uuid).intValue() + coins.intValue()));
  63. }else {
  64. setupPlayer(uuid);
  65. addCoins(uuid, coins);
  66. }
  67. }
  68.  
  69. public static void removeCoins(String uuid, Integer coins) {
  70. if(playerExists(uuid)) {
  71. setCoins(uuid, Integer.valueOf(getCoins(uuid).intValue() - coins.intValue()));
  72. }else {
  73. setupPlayer(uuid);
  74. removeCoins(uuid, coins);
  75. }
  76. }
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement