Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.madebyproxxy.spigot.rc.lobbysystem.coins;
- import me.madebyproxxy.spigot.rc.lobbysystem.Main;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class SQLStats {
- public static boolean playerExists(String uuid) {
- try {
- ResultSet rs = Main.getPlugin(Main.class).mySQL2.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).mySQL2.update("INSERT INTO Stats(UUID, COINS) VALUES ('" + uuid + "', '0');");
- }
- }
- public static Integer getCoins(String uuid) {
- Integer i = 0;
- if(playerExists(uuid)) {
- try {
- ResultSet rs = Main.getPlugin(Main.class).mySQL2.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if((rs.next()) || (Integer.valueOf(rs.getInt("COINS")) == null));
- i = rs.getInt("COINS");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else {
- setupPlayer(uuid);
- getCoins(uuid);
- }
- return i;
- }
- public static void setCoins(String uuid, Integer coins) {
- if(playerExists(uuid)) {
- Main.getPlugin(Main.class).mySQL2.update("UPDATE Stats SET COINS= '" + coins + "' WHERE UUID= '" + uuid + "';");
- }else {
- setupPlayer(uuid);
- setCoins(uuid, coins);
- }
- }
- public static void addCoins(String uuid, Integer coins) {
- if(playerExists(uuid)) {
- setCoins(uuid, Integer.valueOf(getCoins(uuid).intValue() + coins.intValue()));
- }else {
- setupPlayer(uuid);
- addCoins(uuid, coins);
- }
- }
- public static void removeCoins(String uuid, Integer coins) {
- if(playerExists(uuid)) {
- setCoins(uuid, Integer.valueOf(getCoins(uuid).intValue() - coins.intValue()));
- }else {
- setupPlayer(uuid);
- removeCoins(uuid, coins);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement