Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.irazon.honoration.utils;
- import com.irazon.api.rank.RankUtils;
- import org.bukkit.entity.Player;
- import java.io.IOException;
- import java.sql.*;
- /**
- * The MIT License (MIT)
- * Created on 10/08/2016.
- * Copyright (c) 2016 @author iRaZoN_
- */
- public class MySQL {
- private static Connection connection;
- private static String url_base = "jdbc:mysql://", host = "localhost/test", username = "irazon_", password = "mdp";
- public static Connection getConnection() {
- return connection;
- }
- public static boolean isConnected() {
- try {
- if ((connection == null) || (connection.isClosed())) {
- return false;
- } else {
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void connections() {
- if(!isConnected()) {
- try {
- connection = DriverManager.getConnection(url_base + host, username, password);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void deconnection() {
- if(isConnected()) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void createAccount(Player player) {
- MySQL.connections();
- try {
- if(!hasAccount(player)) {
- PreparedStatement sts = MySQL.getConnection().prepareStatement("INSERT INTO sanctions (uuid, rankname, bantime, banreason, banowner, mutetime, mutereason, muteowner) VALUES(?, ?, ?, ?, ?, ?, ?, ?");
- sts.setString(1, player.getUniqueId().toString());
- sts.setString(2, RankUtils.getRank(player).getName());
- sts.setInt(3, 0);
- sts.setString(4, null);
- sts.setString(5, null);
- sts.setInt(6, 0);
- sts.setString(7, null);
- sts.setString(8, null);
- sts.executeUpdate();
- sts.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- public static boolean hasAccount(Player player) {
- MySQL.connections();
- try {
- PreparedStatement sts = MySQL.getConnection().prepareStatement("SELECT uuid FROM sanctions");
- ResultSet result = sts.executeQuery();
- if(result.next()) {
- System.out.println("HASACCOUNT OKEY");
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement