Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ekronia.api.mysql.gamebooster;
- 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 com.ekronia.api.bukkit.utils.game.GameUtils;
- import com.ekronia.api.bungee.utils.GameUtilsBungee;
- public class GameBoosterSQL {
- private String url_base, host, name, username, password, table;
- private Connection connection;
- public GameBoosterSQL(String url_base, String host, String name, String username, String password, String table) {
- this.url_base = url_base;
- this.host = host;
- this.name = name;
- this.username = username;
- this.password = password;
- this.table = table;
- }
- private Connection getConnection() {
- return connection;
- }
- public void connection() {
- if (!isConnected()) {
- try {
- connection = DriverManager.getConnection(url_base + host + "/" + name, username, password);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void deconnection() {
- if (isConnected()) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- private boolean isConnected() {
- try {
- if ((connection == null) || (connection.isClosed()) || (connection.isValid(5))) {
- return false;
- } else {
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public void addGameBooster(GameUtilsBungee game, Timestamp time, int multiplicator){
- try {
- PreparedStatement sts = getConnection().prepareStatement("SELECT game FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- sts = getConnection().prepareStatement("INSERT INTO " + table + " (game, time, multiplicator) VALUES (?, ?, ?)");
- sts.setString(1, game.getName());
- sts.setTimestamp(2, time);
- sts.setInt(3, multiplicator);
- sts.executeUpdate();
- }
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean asBooster(GameUtilsBungee game){
- try {
- PreparedStatement sts = getConnection().prepareStatement("SELECT * FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- return false;
- }
- int booster = rs.getInt("multiplicator");
- sts.close();
- if(booster == 1){
- return false;
- }else{
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public boolean asBoosterBukkit(GameUtils game){
- try {
- PreparedStatement sts = getConnection().prepareStatement("SELECT * FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- return false;
- }
- int booster = rs.getInt("multiplicator");
- sts.close();
- if(booster == 1){
- return false;
- }else{
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public int getMultiplicator(GameUtilsBungee game){
- int multi = 1;
- try {
- PreparedStatement sts = getConnection().prepareStatement("SELECT * FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- return multi;
- }
- multi = rs.getInt("multiplicator");
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return multi;
- }
- public Timestamp getDate(GameUtilsBungee game){
- Timestamp Timestamp = null;
- try {
- PreparedStatement sts = getConnection().prepareStatement("SELECT * FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- return Timestamp;
- }
- Timestamp = rs.getTimestamp("time");
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return Timestamp;
- }
- public void removeGameBooster(GameUtilsBungee game){
- try {
- PreparedStatement sts = getConnection().prepareStatement("DELETE FROM " + table + " WHERE game = ?");
- sts.setString(1, game.getName());
- sts.executeUpdate();
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement