Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.elecsprint73.bdd;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.util.Date;
- import java.util.UUID;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.entity.Player;
- public class BDDconnect {
- private Connection connection;
- String urlbase , host , Database , user , pass;
- public BDDconnect(String urlbase , String host , String Database , String user , String pass) {
- this.urlbase = urlbase;
- this.host = host;
- this.Database = Database;
- this.user = user;
- this.pass = pass;
- }
- public void connection() {
- try {
- connection = (Connection) DriverManager.getConnection(urlbase + host + "/" + Database , user , pass);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean isConnect() {
- return connection != null;
- }
- public void disconnection() {
- if(connection == null) return;
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void createBanDefPlayer(Player p) {
- try {
- PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_player(name,uuid) VALUES(?,?)");
- ps.setString(1, p.getName());
- ps.setString(2, p.getUniqueId().toString());
- ps.execute();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void createBanDefOfflinePlayer(OfflinePlayer p) {
- try {
- PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_player(name,uuid) VALUES(?,?)");
- ps.setString(1, p.getName());
- ps.setString(2, p.getUniqueId().toString());
- ps.execute();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean premiumBanDefPlayer(Player p) {
- try {
- PreparedStatement ps = connection.prepareStatement("SELECT uuid FROM ban_player WHERE uuid= ?");
- ps.setString(1, p.getUniqueId().toString());
- ResultSet resultat = ps.executeQuery();
- boolean isBan = resultat.next();
- ps.close();
- return isBan;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public boolean premiumBanDefOfflinePlayer(OfflinePlayer p) {
- try {
- PreparedStatement ps = connection.prepareStatement("SELECT uuid FROM ban_player WHERE uuid= ?");
- ps.setString(1, p.getUniqueId().toString());
- ResultSet resultat = ps.executeQuery();
- boolean isBan = resultat.next();
- ps.close();
- return isBan;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public void premiumUnbanPlayer(OfflinePlayer p ){
- try {
- PreparedStatement ps = connection.prepareStatement("DELETE FROM ban_player WHERE uuid= ?");
- ps.setString(1, p.getUniqueId().toString());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void premiumTempBanPlayer(Player p, int time) {
- String interval = time +" MINUTE";
- try {
- PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_time_player(name,uuid,expireban) VALUES(?,?,DATE_ADD(NOW(),INTERVAL "+interval+"))");
- ps.setString(1, p.getName());
- ps.setString(2, p.getUniqueId().toString());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean premiumTempBanExpired(Player p) {
- try {
- PreparedStatement ps = connection.prepareStatement("SELECT expireban FROM ban_time_player WHERE uuid= ?");
- ps.setString(1, p.getUniqueId().toString());
- ResultSet resultat = ps.executeQuery();
- resultat.next();
- if(resultat.wasNull()) {
- ps.close();
- return false;
- }else {
- Timestamp now = new Timestamp(new Date().getTime());
- Timestamp expiration = resultat.getTimestamp("expireban");
- boolean expires = expiration.before(now);
- if(expires == false) {
- ps.close();
- return true;
- }else {
- premiumTempUnbanPlayer(p.getUniqueId());
- ps.close();
- return false;
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public void premiumTempBanOfflinePlayer(OfflinePlayer p, int time) {
- String interval = time +" MINUTE";
- try {
- PreparedStatement ps = connection.prepareStatement("INSERT INTO ban_time_player(name,uuid,expireban) VALUES (?,?,DATE_ADD(NOW(),INTERVAL "+ interval +"))");
- ps.setString(1, p.getName());
- ps.setString(2, p.getUniqueId().toString());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void premiumTempUnbanPlayer(UUID u ){
- try {
- PreparedStatement ps = connection.prepareStatement("DELETE FROM ban_time_player WHERE uuid= ?");
- ps.setString(1, u.toString());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement