Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.hyleria.FFA;
- import java.sql.*;
- /**
- * Created by Rob on 19/03/2017.
- */
- public class SQLManager {
- Connection c;
- public void openConnection() {
- try {
- c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/FFA", "root", "");
- Core.getInstance().getLogger().info("Connection established!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean playerExistsInAccounts(String player) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- return rs.getString("player") != null;
- }
- } catch (SQLException e) {
- }
- return false;
- }
- public boolean uuidExistsInAccounts(String uuid) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE uuid= '" + uuid + "'");
- if (rs.next()) {
- return rs.getString("uuid") != null;
- }
- } catch (SQLException e) {
- }
- return false;
- }
- public Connection getConnection() {
- return c;
- }
- public int getGoldenApplesConsumed(String player) {
- int i = 0;
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- i = rs.getInt("goldenapples");
- }
- } catch (SQLException e) {
- }
- }
- return i;
- }
- public int getGoldenHeadsConsumed(String player) {
- int i = 0;
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- i = rs.getInt("goldenheads");
- }
- } catch (SQLException e) {
- }
- }
- return i;
- }
- public int getKills(String player) {
- int i = 0;
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- i = rs.getInt("kills");
- }
- } catch (SQLException e) {
- }
- }
- return i;
- }
- public void updateKills(String player, int i) {
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- s.executeUpdate("UPDATE Accounts SET kills=" + i + " WHERE player = '" + player + "'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public int getDeaths(String player) {
- int i = 0;
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- i = rs.getInt("deaths");
- }
- rs.close();
- } catch (SQLException e) {
- }
- }
- return i;
- }
- public void updateDeaths(String player, int i) {
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- s.executeUpdate("UPDATE Accounts SET deaths=" + i + " WHERE player='" + player + "'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void updateConsumedGA(String player, int i) {
- if (playerExistsInAccounts(player)) {
- try {
- Statement s = getConnection().createStatement();
- s.executeUpdate("UPDATE Accounts SET goldenapples=" + i + " WHERE player='" + player + "'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void wipeStats() {
- }
- public void createNewProfileInAccounts(String playern, String uuid, int kills, int deaths, int goldenapples, int goldenheads) {
- try {
- Statement s = getConnection().createStatement();
- s.executeUpdate("INSERT INTO Accounts(player, uuid, kills, deaths, goldenapples, goldenheads) VALUES('" + playern + "', '" + uuid + "', '" + kills + "', '" + deaths + "', '" + goldenapples +"', '" + goldenheads + "');");
- Core.getInstance().getServer().getLogger().info("[FFA] Successfully created new profile in accounts for player '" + playern + "'");
- } catch (Exception e) {
- e.printStackTrace();
- Core.getInstance().getServer().getLogger().info("Failed to create profile in accounts for player '" + playern + "'");
- }
- }
- public String getUUID(String player) {
- String uuid = "";
- if (playerExistsInAccounts(player) == true) {
- try {
- Statement s = getConnection().createStatement();
- ResultSet rs = s.executeQuery("SELECT * FROM Accounts WHERE player= '" + player + "'");
- if (rs.next()) {
- uuid = rs.getString("uuid");
- }
- } catch (SQLException e) {
- }
- }
- return uuid;
- }
- }
Add Comment
Please, Sign In to add comment