Guest User

Untitled

a guest
Dec 19th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.16 KB | None | 0 0
  1. package me.madebyproxxy.spigot.knockffa.utils;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import me.madebyproxxy.spigot.knockffa.main.Main;
  7.  
  8. public class SQLStats {
  9.    
  10.     public static boolean playerExists(String uuid) {
  11.         try {
  12.             ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  13.             if(rs.next()) {
  14.                 return rs.getString("UUID") != null;
  15.             }
  16.             return false;
  17.         }catch (SQLException e) {
  18.             e.printStackTrace();
  19.         }
  20.        
  21.         return false;  
  22.     }
  23.    
  24.     public static void setupPlayer(String uuid) {
  25.         if(!(playerExists(uuid))) {
  26.             Main.getPlugin(Main.class).mySQL.update("INSERT INTO Stats(UUID, GAMES, WINS) VALUES ('" + uuid + "', '0', '0');");
  27.         }
  28.     }
  29.    
  30.     public static Integer getKills(String uuid) {
  31.         Integer i = 0;
  32.        
  33.         if(playerExists(uuid)) {
  34.             try {
  35.                 ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  36.                 if((rs.next()) || (Integer.valueOf(rs.getInt("GAMES")) == null));
  37.                    
  38.                 i = rs.getInt("GAMES");
  39.             } catch (SQLException e) {
  40.                 e.printStackTrace();
  41.             }
  42.         }else {
  43.             setupPlayer(uuid);
  44.             getKills(uuid);
  45.         }
  46.        
  47.         return i;
  48.     }
  49.    
  50.     public static Integer getDeaths(String uuid) {
  51.         Integer i = 0;
  52.        
  53.         if(playerExists(uuid)) {
  54.             try {
  55.                 ResultSet rs = Main.getPlugin(Main.class).mySQL.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
  56.                 if((rs.next()) || (Integer.valueOf(rs.getInt("WINS")) == null));
  57.                    
  58.                 i = rs.getInt("WINS");
  59.             } catch (SQLException e) {
  60.                 e.printStackTrace();
  61.             }
  62.         }else {
  63.             setupPlayer(uuid);
  64.             getDeaths(uuid);
  65.         }
  66.        
  67.         return i;
  68.     }
  69.    
  70.     public static void setKills(String uuid, Integer games) {
  71.         if(playerExists(uuid)) {
  72.             Main.getPlugin(Main.class).mySQL.update("UPDATE Stats SET GAMES= '" + games + "' WHERE UUID= '" + uuid + "';");
  73.         }else {
  74.             setupPlayer(uuid);
  75.             setKills(uuid, games);
  76.         }
  77.     }
  78.    
  79.     public static void setDeaths(String uuid, Integer wins) {
  80.         if(playerExists(uuid)) {
  81.             Main.getPlugin(Main.class).mySQL.update("UPDATE Stats SET WINS= '" + wins + "' WHERE UUID= '" + uuid + "';");
  82.         }else {
  83.             setupPlayer(uuid);
  84.             setDeaths(uuid, wins);
  85.         }
  86.     }
  87.    
  88.     public static void addKills(String uuid, Integer games) {
  89.         if(playerExists(uuid)) {
  90.             setKills(uuid, Integer.valueOf(getKills(uuid).intValue() + games.intValue()));
  91.         }else {
  92.             setupPlayer(uuid);
  93.             addKills(uuid, games);
  94.         }
  95.     }
  96.    
  97.     public static void addDeaths(String uuid, Integer wins) {
  98.         if(playerExists(uuid)) {
  99.             setDeaths(uuid, Integer.valueOf(getDeaths(uuid).intValue() + wins.intValue()));
  100.         }else {
  101.             setupPlayer(uuid);
  102.             addDeaths(uuid, wins);
  103.         }
  104.     }
  105.    
  106.     public static void removeKills(String uuid, Integer games) {
  107.         if(playerExists(uuid)) {
  108.             setKills(uuid, Integer.valueOf(getKills(uuid).intValue() - games.intValue()));
  109.         }else {
  110.             setupPlayer(uuid);
  111.             removeKills(uuid, games);
  112.         }
  113.     }
  114.    
  115.     public static void removeDeaths(String uuid, Integer wins) {
  116.         if(playerExists(uuid)) {
  117.             setDeaths(uuid, Integer.valueOf(getDeaths(uuid).intValue() - wins.intValue()));
  118.         }else {
  119.             setupPlayer(uuid);
  120.             removeDeaths(uuid, wins);
  121.         }
  122.     }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment