Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. package fr.elecsprint73.bdd;
  2.  
  3. import java.sql.Connection;
  4.  
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Timestamp;
  10. import java.util.Date;
  11. import java.util.UUID;
  12.  
  13. import org.bukkit.OfflinePlayer;
  14. import org.bukkit.entity.Player;
  15.  
  16.  
  17. public class BDDconnect {
  18.  
  19. private Connection connection;
  20. String urlbase , host , Database , user , pass;
  21.  
  22. public BDDconnect(String urlbase , String host , String Database , String user , String pass) {
  23.  
  24. this.urlbase = urlbase;
  25. this.host = host;
  26. this.Database = Database;
  27. this.user = user;
  28. this.pass = pass;
  29. }
  30.  
  31. public void connection() {
  32. try {
  33. connection = (Connection) DriverManager.getConnection(urlbase + host + "/" + Database , user , pass);
  34. } catch (SQLException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. public boolean isConnect() {
  40. return connection != null;
  41. }
  42.  
  43. public void disconnection() {
  44.  
  45. if(connection == null) return;
  46.  
  47. try {
  48. connection.close();
  49. } catch (SQLException e) {
  50. e.printStackTrace();
  51. }
  52.  
  53. }
  54.  
  55. public void createBanDefPlayer(Player p) {
  56.  
  57. try {
  58. PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_player(name,uuid) VALUES(?,?)");
  59. ps.setString(1, p.getName());
  60. ps.setString(2, p.getUniqueId().toString());
  61. ps.execute();
  62. ps.close();
  63.  
  64. } catch (SQLException e) {
  65. e.printStackTrace();
  66. }
  67.  
  68. }
  69.  
  70. public void createBanDefOfflinePlayer(OfflinePlayer p) {
  71.  
  72. try {
  73. PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_player(name,uuid) VALUES(?,?)");
  74. ps.setString(1, p.getName());
  75. ps.setString(2, p.getUniqueId().toString());
  76. ps.execute();
  77. ps.close();
  78.  
  79. } catch (SQLException e) {
  80. e.printStackTrace();
  81. }
  82. }
  83.  
  84. public boolean premiumBanDefPlayer(Player p) {
  85. try {
  86.  
  87. PreparedStatement ps = connection.prepareStatement("SELECT uuid FROM ban_player WHERE uuid= ?");
  88. ps.setString(1, p.getUniqueId().toString());
  89. ResultSet resultat = ps.executeQuery();
  90. boolean isBan = resultat.next();
  91. ps.close();
  92. return isBan;
  93.  
  94. } catch (SQLException e) {
  95. e.printStackTrace();
  96. }
  97. return false;
  98. }
  99.  
  100. public boolean premiumBanDefOfflinePlayer(OfflinePlayer p) {
  101.  
  102. try {
  103.  
  104. PreparedStatement ps = connection.prepareStatement("SELECT uuid FROM ban_player WHERE uuid= ?");
  105. ps.setString(1, p.getUniqueId().toString());
  106. ResultSet resultat = ps.executeQuery();
  107. boolean isBan = resultat.next();
  108. ps.close();
  109. return isBan;
  110.  
  111. } catch (SQLException e) {
  112. e.printStackTrace();
  113. }
  114.  
  115. return false;
  116.  
  117. }
  118. public void premiumUnbanPlayer(OfflinePlayer p ){
  119.  
  120. try {
  121. PreparedStatement ps = connection.prepareStatement("DELETE FROM ban_player WHERE uuid= ?");
  122. ps.setString(1, p.getUniqueId().toString());
  123. ps.executeUpdate();
  124. ps.close();
  125.  
  126. } catch (SQLException e) {
  127. e.printStackTrace();
  128. }
  129.  
  130. }
  131. public void premiumTempBanPlayer(Player p, int time) {
  132.  
  133. String interval = time +" MINUTE";
  134.  
  135. try {
  136. PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_time_player(name,uuid,expireban) VALUES(?,?,DATE_ADD(NOW(),INTERVAL "+interval+"))");
  137. ps.setString(1, p.getName());
  138. ps.setString(2, p.getUniqueId().toString());
  139. ps.executeUpdate();
  140. ps.close();
  141. } catch (SQLException e) {
  142. e.printStackTrace();
  143. }
  144. }
  145. public boolean premiumTempBanExpired(Player p) {
  146.  
  147. try {
  148.  
  149. PreparedStatement ps = connection.prepareStatement("SELECT expireban FROM ban_time_player WHERE uuid= ?");
  150. ps.setString(1, p.getUniqueId().toString());
  151.  
  152. ResultSet resultat = ps.executeQuery();
  153. resultat.next();
  154.  
  155. if(resultat.wasNull()) {
  156. ps.close();
  157. return false;
  158. }else {
  159.  
  160. Timestamp now = new Timestamp(new Date().getTime());
  161. Timestamp expiration = resultat.getTimestamp("expireban");
  162. boolean expires = expiration.before(now);
  163.  
  164. if(expires == false) {
  165. ps.close();
  166. return true;
  167. }else {
  168. premiumTempUnbanPlayer(p.getUniqueId());
  169. ps.close();
  170. return false;
  171. }
  172. }
  173. } catch (SQLException e) {
  174. e.printStackTrace();
  175. }
  176.  
  177. return false;
  178. }
  179.  
  180. public void premiumTempBanOfflinePlayer(OfflinePlayer p, int time) {
  181.  
  182. String interval = time +" MINUTE";
  183.  
  184. try {
  185. PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_time_player(name,uuid,expireban) VALUES (?,?,DATE_ADD(NOW(),INTERVAL "+ interval +"))");
  186. ps.setString(1, p.getName());
  187. ps.setString(2, p.getUniqueId().toString());
  188. ps.executeUpdate();
  189. ps.close();
  190. } catch (SQLException e) {
  191. e.printStackTrace();
  192. }
  193. }
  194. public void premiumTempUnbanPlayer(UUID u ){
  195.  
  196. try {
  197. PreparedStatement ps = connection.prepareStatement("DELETE FROM ban_time_player WHERE uuid= ?");
  198. ps.setString(1, u.toString());
  199. ps.executeUpdate();
  200. ps.close();
  201.  
  202. } catch (SQLException e) {
  203. e.printStackTrace();
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement