Advertisement
Guest User

MySQL

a guest
Apr 13th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. public static Connection con;
  4.  
  5. public static void connect(){
  6. if(!isConnected()){
  7. try {
  8. con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Server?autoReconnect=true", "root", "DasPasswortIstFürHacker");
  9. BungeeCord.getInstance().broadcast("§aDie MySQL Verbindung wurde auf gebaut!");
  10. } catch (SQLException e) {
  11. // TODO Auto-generated catch block
  12. e.printStackTrace();
  13. }
  14. }
  15. }
  16. public static void disconnect() {
  17. if(isConnected()){
  18. try {
  19. con.close();
  20. BungeeCord.getInstance().broadcast("§cDie MySQL Verbindung wurde getrennt!");
  21. } catch (SQLException e) {
  22. // TODO Auto-generated catch block
  23. e.printStackTrace();
  24. }
  25. }
  26. }
  27. public static boolean isConnected() {
  28. return (con != null);
  29. }
  30.  
  31.  
  32. public static boolean playerExists(ProxiedPlayer p , UUID uuid){
  33. try {
  34. PreparedStatement ps = MySQL.con.prepareStatement("SELECT * from Verify Where UUID = ?");
  35. ps.setString(1, uuid.toString());
  36. ResultSet rs = ps.executeQuery();
  37. if(rs.next()){
  38. return rs.getString("UUID") != null;
  39. }
  40. rs.close();
  41. return false;
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45. return false;
  46. }
  47.  
  48. public static void update(String qry){
  49. if(isConnected()){
  50. try {
  51. con.createStatement().executeUpdate(qry);
  52. } catch (SQLException e) {
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57.  
  58. public static void CheckUser(ProxiedPlayer p, UUID uuid) {
  59.  
  60. try {
  61. if(!playerExists(p, uuid)){
  62. if(p.hasPermission("*")){
  63. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Admin');");
  64. ps.executeUpdate();
  65. }else if(p.hasPermission("system.prefix.mod")){
  66. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Moderator');");
  67. ps.executeUpdate();
  68. }else if(p.hasPermission("system.prefix.sup")){
  69. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Supporter');");
  70. ps.executeUpdate();
  71. }else if(p.hasPermission("system.prefix.srsup")){
  72. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','SrSupporter');");
  73. ps.executeUpdate();
  74. }else if(p.hasPermission("system.prefix.jrsup")){
  75. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','JrSupporter');");
  76. ps.executeUpdate();
  77. }else if(p.hasPermission("system.prefix.builder")){
  78. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Builder');");
  79. ps.executeUpdate();
  80. }else if(p.hasPermission("system.prefix.yt")){
  81. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Youtube');");
  82. ps.executeUpdate();
  83. }else if(p.hasPermission("system.prefix.vip")){
  84. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','VIP');");
  85. ps.executeUpdate();
  86. }else if(p.hasPermission("system.prefix.srmod")){
  87. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','SrModerator');");
  88. ps.executeUpdate();
  89. }else if(p.hasPermission("system.prefix.srmod")){
  90. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','SrModerator');");
  91. ps.executeUpdate();
  92. }else if(p.hasPermission("system.prefix.testsup")){
  93. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Test-Supporter');");
  94. ps.executeUpdate();
  95. }else{
  96. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' ','Spieler');");
  97. ps.executeUpdate();
  98. }
  99. }
  100. } catch (SQLException e) {
  101. // TODO Auto-generated catch block
  102. e.printStackTrace();
  103. }
  104.  
  105. }
  106. public static void UpdateUser(ProxiedPlayer p, UUID uuid, String tsid) {
  107.  
  108. try {
  109. if(!playerExists(p, uuid)){
  110. if(p.hasPermission("*")){
  111. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"','" + tsid + "','Admin');");
  112. ps.executeUpdate();
  113. }else if(p.hasPermission("system.prefix.mod")){
  114. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"','" + tsid +"','Moderator');");
  115. ps.executeUpdate();
  116. }else if(p.hasPermission("system.prefix.sup")){
  117. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid +" ','Supporter');");
  118. ps.executeUpdate();
  119. }else if(p.hasPermission("system.prefix.srsup")){
  120. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid + " ','SrSupporter');");
  121. ps.executeUpdate();
  122. }else if(p.hasPermission("system.prefix.jrsup")){
  123. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid +" ','JrSupporter');");
  124. ps.executeUpdate();
  125. }else if(p.hasPermission("system.prefix.builder")){
  126. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid + " ','Builder');");
  127. ps.executeUpdate();
  128. }else if(p.hasPermission("system.prefix.yt")){
  129. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid +" ','Youtube');");
  130. ps.executeUpdate();
  131. }else if(p.hasPermission("system.prefix.vip")){
  132. PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' "+ tsid +" ','VIP');");
  133. ps.executeUpdate();
  134. }else if(p.hasPermission("system.prefix.srmod")){
  135. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid + " ','SrModerator');");
  136. ps.executeUpdate();
  137. }else if(p.hasPermission("system.prefix.srmod")){
  138. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid +" ','SrModerator');");
  139. ps.executeUpdate();
  140. }else if(p.hasPermission("system.prefix.testsup")){
  141. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"','" +tsid+"','Test-Supporter');");
  142. ps.executeUpdate();
  143. }else{
  144. PreparedStatement ps = MySQL.con.prepareStatement("INSERT INTO Verify (UUID,tsid,Rang) VALUES ('"+uuid+"',' " + tsid +" ','Spieler');");
  145. ps.executeUpdate();
  146. }
  147. }
  148. } catch (SQLException e) {
  149. // TODO Auto-generated catch block
  150. e.printStackTrace();
  151. }
  152.  
  153. }
  154.  
  155. public static ResultSet getResult(String qry){
  156. if(isConnected()){
  157. try {
  158. return con.createStatement().executeQuery(qry);
  159. } catch (SQLException e) {
  160. e.printStackTrace();
  161. }
  162. }
  163. return null;
  164. }
  165. public static void removeID(ProxiedPlayer p, UUID uuid){
  166. try {
  167. if(playerExists(p, p.getUniqueId())){
  168. PreparedStatement ps = MySQL.con.prepareStatement("DELETE FROM Verify WHERE UUID = ?");
  169. ps.setString(1, uuid.toString());
  170. ps.executeUpdate();
  171. p.sendMessage(Main.pr + "Du hast erfolgreich deinen Minecraft Account von deinem Teamspeak Account getrennt.");
  172. }else if(!playerExists(p, p.getUniqueId())){
  173. p.sendMessage(Main.pr + "Du bist nicht verifiziert.");
  174. }
  175. } catch (SQLException e) {
  176. e.printStackTrace();
  177. }
  178. }
  179. public static void setID(ProxiedPlayer p, String id){
  180. try {
  181. PreparedStatement ps = MySQL.con.prepareStatement("UPDATE Verify SET tsid = '"+id+"' WHERE UUID = '"+p.getUniqueId()+"'");
  182. ps.executeUpdate();
  183. } catch (SQLException e) {
  184. // TODO Auto-generated catch block
  185. e.printStackTrace();
  186. }
  187. }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement