Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.madebyproxxy.spigot.knockffa.utils;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import me.madebyproxxy.spigot.knockffa.main.Main;
- public class SQLStats {
- public static boolean playerExists(String uuid) {
- try {
- ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if(rs.next()) {
- return rs.getString("UUID") != null;
- }
- return false;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void setupPlayer(String uuid) {
- if(!(playerExists(uuid))) {
- Main.getPlugin(Main.class).mySQL.update("INSERT INTO Stats(UUID, GAMES, WINS) VALUES ('" + uuid + "', '0', '0');");
- }
- }
- public static Integer getKills(String uuid) {
- Integer i = 0;
- if(playerExists(uuid)) {
- try {
- ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if((rs.next()) || (Integer.valueOf(rs.getInt("GAMES")) == null));
- i = rs.getInt("GAMES");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else {
- setupPlayer(uuid);
- getKills(uuid);
- }
- return i;
- }
- public static Integer getDeaths(String uuid) {
- Integer i = 0;
- if(playerExists(uuid)) {
- try {
- ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if((rs.next()) || (Integer.valueOf(rs.getInt("WINS")) == null));
- i = rs.getInt("WINS");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else {
- setupPlayer(uuid);
- getDeaths(uuid);
- }
- return i;
- }
- public static void setKills(String uuid, Integer games) {
- if(playerExists(uuid)) {
- Main.getPlugin(Main.class).mySQL.update("UPDATE Stats SET GAMES= '" + games + "' WHERE UUID= '" + uuid + "';");
- }else {
- setupPlayer(uuid);
- setKills(uuid, games);
- }
- }
- public static void setDeaths(String uuid, Integer wins) {
- if(playerExists(uuid)) {
- Main.getPlugin(Main.class).mySQL.update("UPDATE Stats SET WINS= '" + wins + "' WHERE UUID= '" + uuid + "';");
- }else {
- setupPlayer(uuid);
- setDeaths(uuid, wins);
- }
- }
- public static void addKills(String uuid, Integer games) {
- if(playerExists(uuid)) {
- setKills(uuid, Integer.valueOf(getKills(uuid).intValue() + games.intValue()));
- }else {
- setupPlayer(uuid);
- addKills(uuid, games);
- }
- }
- public static void addDeaths(String uuid, Integer wins) {
- if(playerExists(uuid)) {
- setDeaths(uuid, Integer.valueOf(getDeaths(uuid).intValue() + wins.intValue()));
- }else {
- setupPlayer(uuid);
- addDeaths(uuid, wins);
- }
- }
- public static void removeKills(String uuid, Integer games) {
- if(playerExists(uuid)) {
- setKills(uuid, Integer.valueOf(getKills(uuid).intValue() - games.intValue()));
- }else {
- setupPlayer(uuid);
- removeKills(uuid, games);
- }
- }
- public static void removeDeaths(String uuid, Integer wins) {
- if(playerExists(uuid)) {
- setDeaths(uuid, Integer.valueOf(getDeaths(uuid).intValue() - wins.intValue()));
- }else {
- setupPlayer(uuid);
- removeDeaths(uuid, wins);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment