Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package net.jlpcrew.lobbyscoreboard;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.UUID;
  7.  
  8. public class MySQLPunkte {
  9.  
  10. public static boolean isUserExists(UUID uuid) {
  11.  
  12. try {
  13.  
  14. PreparedStatement st = MySQL.con.prepareStatement("SELECT Punkte FROM PunkteSystem WHERE UUID = ?");
  15. st.setString(1, uuid.toString());
  16. ResultSet rs = st.executeQuery();
  17. return rs.next();
  18.  
  19. } catch(SQLException e) {
  20.  
  21. e.printStackTrace();
  22.  
  23. }
  24.  
  25. return false;
  26.  
  27. }
  28.  
  29. public static int getPoints(UUID uuid) {
  30.  
  31. try {
  32.  
  33. PreparedStatement st = MySQL.con.prepareStatement("SELECT Punkte FROM PunkteSystem WHERE UUID = ?");
  34. st.setString(1, uuid.toString());
  35. ResultSet rs = st.executeQuery();
  36.  
  37. while (rs.next()) {
  38.  
  39. return rs.getInt("Punkte");
  40.  
  41. }
  42.  
  43. } catch (SQLException e) {
  44.  
  45. e.printStackTrace();
  46.  
  47. }
  48.  
  49. return -1;
  50.  
  51. }
  52.  
  53. public static void setPoints(UUID uuid, int points) {
  54.  
  55. if(getPoints(uuid) == -1) {
  56.  
  57. try {
  58.  
  59. PreparedStatement st = MySQL.con.prepareStatement("INSERT INTO PunkteSystem (UUID,Punkte) VALUES (?,?)");
  60. st.setString(1, uuid.toString());
  61. st.setInt(2, points);
  62. st.executeUpdate();
  63.  
  64. } catch (SQLException e) {
  65.  
  66. e.printStackTrace();
  67.  
  68. }
  69.  
  70. } else {
  71. try {
  72.  
  73. PreparedStatement st = MySQL.con.prepareStatement("UPDATE PunkteSystem set Punkte = ? WHERE UUID = ?");
  74. st.setString(2, uuid.toString());
  75. st.setInt(1, points);
  76. st.executeUpdate();
  77.  
  78. } catch (SQLException e) {
  79.  
  80. e.printStackTrace();
  81.  
  82. }
  83.  
  84. }
  85.  
  86. }
  87.  
  88. public static void addPoints(UUID uuid, int points) {
  89.  
  90. int current = getPoints(uuid);
  91.  
  92. setPoints(uuid, points + current);
  93.  
  94. }
  95.  
  96. public static void removePoints(UUID uuid, int points) {
  97.  
  98. int current = getPoints(uuid);
  99.  
  100. setPoints(uuid, current - points);
  101.  
  102. }
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement