notjacob

PlayerHandler.java

Jan 4th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.15 KB | None | 0 0
  1. package skywars.notjacob.handlers;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.configuration.file.YamlConfiguration;
  7. import org.bukkit.entity.Player;
  8.  
  9. public class playerHandler {
  10.     private fileHandler fh;
  11.     private islandYML isY;
  12.    
  13.     public void setup(Player p) throws IOException {
  14.        
  15.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  16.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  17.         f.createNewFile();
  18.         yml.addDefault("ELO", 100);
  19.         yml.addDefault("wins", 0);
  20.         yml.addDefault("losses", 0);
  21.         yml.addDefault("kills", 0);
  22.         yml.addDefault("deaths", 0);
  23.         yml.addDefault("ingame", false);
  24.         yml.addDefault("island", 0);
  25.         yml.addDefault("dead", false);
  26.         yml.options().copyDefaults(true);
  27.         yml.save(f);
  28.     }
  29.     public float elo(Player p) {
  30.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  31.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  32.         return yml.getInt("ELO");
  33.     }
  34.     public boolean ingame(Player p) {
  35.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  36.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  37.         return yml.getBoolean("ingame") ? true : false;
  38.     }
  39.     public float wins(Player p) {
  40.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  41.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  42.         return yml.getInt("wins");
  43.     }
  44.     public float losses(Player p) {
  45.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  46.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  47.         return yml.getInt("losses");
  48.     }
  49.     public float kills(Player p) {
  50.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  51.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  52.         return yml.getInt("kills");
  53.     }
  54.     public float deaths(Player p) {
  55.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  56.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  57.         return yml.getInt("deaths");
  58.     }
  59.     public Island island(Player player) {
  60.         File f = new File(fh.path + "users/" + player.getUniqueId().toString() + ".yml");
  61.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  62.         return new Island(yml.getInt("island"), (SkywarsPlayer) player, isY.getLocation(yml.getInt("island")));
  63.     }
  64.     public void delete(Player p) {
  65.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  66.         f.delete();
  67.     }
  68.     public boolean dead(Player p) {
  69.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  70.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  71.         return yml.getBoolean("dead");
  72.     }
  73.     public void setElo(float elo, Player p) {
  74.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  75.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  76.         yml.set("ELO", elo);
  77.         try {
  78.             yml.save(f);
  79.         } catch (IOException e) {
  80.             e.printStackTrace();
  81.         }
  82.     }
  83.     public void setDead(boolean dead, Player p) {
  84.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  85.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  86.         yml.set("dead", dead);
  87.         try {
  88.             yml.save(f);
  89.         } catch (IOException e) {
  90.             e.printStackTrace();
  91.         }
  92.     }
  93.     public void setWins(float wins, Player p) {
  94.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  95.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  96.         yml.set("wins", wins);
  97.         try {
  98.             yml.save(f);
  99.         } catch (IOException e) {
  100.             e.printStackTrace();
  101.         }
  102.     }
  103.     public void setLosses(float losses, Player p) {
  104.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  105.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  106.         yml.set("losses", losses);
  107.         try {
  108.             yml.save(f);
  109.         } catch (IOException e) {
  110.             e.printStackTrace();
  111.         }
  112.     }
  113.     public void setDeaths(float deaths, Player p) {
  114.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  115.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  116.         yml.set("deaths", deaths);
  117.         try {
  118.             yml.save(f);
  119.         } catch (IOException e) {
  120.             e.printStackTrace();
  121.         }
  122.     }
  123.     public void setKills(float kills, Player p) {
  124.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  125.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  126.         yml.set("kills", kills);
  127.         try {
  128.             yml.save(f);
  129.         } catch (IOException e) {
  130.             e.printStackTrace();
  131.         }
  132.     }
  133.     public void setIngame(boolean ingame, Player p) {
  134.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  135.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  136.         yml.set("ingame", ingame);
  137.         try {
  138.             yml.save(f);
  139.         } catch (IOException e) {
  140.             e.printStackTrace();
  141.         }
  142.        
  143.     }
  144.     public void setIsland(float id, Player p) {
  145.         File f = new File(fh.path + "users/" + p.getUniqueId().toString() + ".yml");
  146.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  147.         yml.set("island", id);
  148.         try {
  149.             yml.save(f);
  150.         } catch (IOException e) {
  151.             e.printStackTrace();
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment