Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. package de.teamsoul.main.mysql;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. public class methoden_coinsystem {
  8.  
  9. public static boolean UserExists(String UID) {
  10. try {
  11. PreparedStatement ps = mysql.getConnection().prepareStatement("SELECT * FROM CoinSystem WHERE UID = ?");
  12. ps.setString(1, UID);
  13. ResultSet rs = ps.executeQuery();
  14. return rs.next();
  15. } catch (SQLException e) {
  16. e.printStackTrace();
  17. }
  18. return false;
  19. }
  20.  
  21. public static void addCoins(int Coins, String UID, String Name) {
  22.  
  23. if (UserExists(UID)) {
  24.  
  25. try {
  26. PreparedStatement ps_upCoins = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Coins = Coins + ? WHERE UID = ?");
  27. ps_upCoins.setInt(1, Coins);
  28. ps_upCoins.setString(2, UID);
  29. ps_upCoins.executeUpdate();
  30.  
  31. PreparedStatement ps_upName = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Name = ? WHERE UID = ?");
  32. ps_upName.setString(1, Name);
  33. ps_upName.setString(2, UID);
  34. ps_upName.executeUpdate();
  35. } catch (SQLException e) {
  36. e.printStackTrace();
  37. }
  38.  
  39. } else {
  40.  
  41. try {
  42. PreparedStatement ps = mysql.getConnection().prepareStatement("INSERT INTO CoinSystem (Name,UID,Coins,DailyCoinsAvailable) VALUES (?,?,?,?)");
  43. ps.setString(1, Name);
  44. ps.setString(2, UID);
  45. ps.setInt(3, Coins);
  46. ps.setBoolean(4, true);
  47. ps.executeUpdate();
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51.  
  52. }
  53.  
  54. }
  55.  
  56. public static void removeCoins(String UID, int Coins) {
  57. if (UserExists(UID)) {
  58. try {
  59. PreparedStatement ps_remove = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Coins = Coins - ? WHERE UID = ?");
  60. ps_remove.setInt(1, Coins);
  61. ps_remove.setString(2, UID);
  62. ps_remove.executeUpdate();
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }
  68.  
  69. public static int getConis(String UID) {
  70. try {
  71. PreparedStatement ps = mysql.getConnection().prepareStatement("SELECT Coins FROM CoinSystem WHERE UID = ?");
  72. ps.setString(1, UID);
  73.  
  74. ResultSet rs = ps.executeQuery();
  75. if (rs.next()) {
  76. return rs.getInt("Coins");
  77. }
  78. } catch (SQLException e) {
  79. e.printStackTrace();
  80. }
  81. return -1;
  82. }
  83.  
  84. public static boolean ifDailyBonusAvailable(String UID) {
  85. try {
  86. PreparedStatement ps = mysql.getConnection().prepareStatement("SELECT DailyCoinsAvailable FROM CoinSystem WHERE UID = ?");
  87. ps.setString(1, UID);
  88. ResultSet rs = ps.executeQuery();
  89. if (rs.next()) {
  90. return rs.getBoolean("DailyCoinsAvailable");
  91. }
  92. } catch (SQLException e) {
  93. e.printStackTrace();
  94. }
  95. return false;
  96. }
  97.  
  98. public static void deactivateDailyBonus(String UID) {
  99. try {
  100. PreparedStatement ps = mysql.getConnection().prepareStatement("UPDATE `CoinSystem` SET `DailyCoinsAvailable`='0' WHERE UID = ?");
  101. ps.setString(1, UID);
  102. ps.executeUpdate();
  103. } catch (SQLException e) {
  104. e.printStackTrace();
  105. }
  106. }
  107.  
  108. public static void activateAllDilayBonusses() {
  109. try {
  110.  
  111. PreparedStatement ps = mysql.getConnection().prepareStatement("UPDATE `CoinSystem` SET DailyCoinsAvailable = true WHERE DailyCoinsAvailable = false");
  112. ps.executeUpdate();
  113.  
  114. } catch (SQLException e) {
  115. e.printStackTrace();
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement