Advertisement
Guest User

PlayerData.java

a guest
Aug 1st, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.45 KB | None | 0 0
  1. package DCNetwork.KitPVP.Player;
  2.  
  3. import DCNetwork.KitPVP.KitPVP;
  4. import DCNetwork.KitPVP.Util.YMLFactory;
  5. import org.bukkit.Material;
  6. import org.bukkit.configuration.ConfigurationSection;
  7. import org.bukkit.entity.Player;
  8.  
  9. import java.io.File;
  10.  
  11. /**
  12.  * Created by Luke on 25/07/2014.
  13.  */
  14. public class PlayerData {
  15.     private YMLFactory.YML dataFile;
  16.     private Player player;
  17.  
  18.     private void refreshConfig() {
  19.         dataFile.saveConfig();
  20.     }
  21.  
  22.     public PlayerData(Player player) {
  23.         this.player = player;
  24.  
  25.         File data = new File(KitPVP.instance.getDataFolder(), "data");
  26.         if(!data.exists()){
  27.             data.mkdir();
  28.         }
  29.  
  30.         dataFile = YMLFactory.buildYML("data" + File.separator + player.getUniqueId().toString() + ".data", KitPVP.instance);
  31.         refreshConfig();
  32.     }
  33.  
  34.     private void check() {
  35.  
  36.         if (!dataFile.getConfig().contains("kills")) {
  37.             dataFile.getConfig().set("kills", 0);
  38.         }
  39.         if (!dataFile.getConfig().contains("deaths")) {
  40.             dataFile.getConfig().set("deaths", 0);
  41.         }
  42.         if (!dataFile.getConfig().contains("highestKillStreak")) {
  43.             dataFile.getConfig().set("highestKillStreak", 0);
  44.         }
  45.         if (!dataFile.getConfig().contains("currentKillStreak")) {
  46.             dataFile.getConfig().set("currentKillStreak", 0);
  47.         }
  48.         if (!dataFile.getConfig().contains("lastKitUsed")) {
  49.             dataFile.getConfig().set("lastKitUsed", "fisherBob");
  50.         }
  51.  
  52.         if (!dataFile.getConfig().contains("kitdata")) {
  53.             dataFile.getConfig().createSection("kitdata");
  54.  
  55.                 dataFile.getConfig().getConfigurationSection("kitdata").set("fisherBob", true);
  56.                 dataFile.getConfig().getConfigurationSection("kitdata").set("2", false);
  57.                 dataFile.getConfig().getConfigurationSection("kitdata").set("3", false);
  58.                 dataFile.getConfig().getConfigurationSection("kitdata").set("4", false);
  59.                 dataFile.getConfig().getConfigurationSection("kitdata").set("5", false);
  60.                 dataFile.getConfig().getConfigurationSection("kitdata").set("6", false);
  61.                 dataFile.getConfig().getConfigurationSection("kitdata").set("7", false);
  62.                 dataFile.getConfig().getConfigurationSection("kitdata").set("8", false);
  63.                 dataFile.getConfig().getConfigurationSection("kitdata").set("9", false);
  64.                 dataFile.getConfig().getConfigurationSection("kitdata").set("10", false);
  65.         }
  66.         refreshConfig();
  67.     }
  68.  
  69.     public void setKit(String kitID, boolean value) {
  70.         dataFile.getConfig().getConfigurationSection("kitdata").set(kitID, value);
  71.         refreshConfig();
  72.     }
  73.  
  74.     public boolean getKit(String kitID) {
  75.         return dataFile.getConfig().getConfigurationSection("kitdata").getBoolean(kitID);
  76.     }
  77.  
  78.     public void setKills(int kills) {
  79.         refreshConfig();
  80.         dataFile.getConfig().set("kills", kills);
  81.     }
  82.  
  83.     public int getKills() {
  84.         return dataFile.getConfig().getInt("kills");
  85.     }
  86.  
  87.     public void setDeaths(int deaths) {
  88.         dataFile.getConfig().set("deaths", deaths);
  89.         refreshConfig();
  90.     }
  91.  
  92.     public int getDeaths() {
  93.         return dataFile.getConfig().getInt("deaths");
  94.     }
  95.  
  96.     public void setHighestKillStreak(int highestKillStreak) {
  97.         dataFile.getConfig().set("highestKillStreak", highestKillStreak);
  98.         refreshConfig();
  99.     }
  100.  
  101.     public int getHighestKillStreak() {
  102.         return dataFile.getConfig().getInt("highestKillStreak");
  103.     }
  104.  
  105.     public void setCurrentKillStreak(int currentKillStreak) {
  106.         dataFile.getConfig().set("currentKillStreak", currentKillStreak);
  107.         if (currentKillStreak > getHighestKillStreak()) {
  108.             setHighestKillStreak(currentKillStreak);
  109.         }
  110.         refreshConfig();
  111.     }
  112.  
  113.     public int getCurrentKillStreak() {
  114.         return dataFile.getConfig().getInt("currentKillStreak");
  115.     }
  116.  
  117.     public void setLastKitUsed(String kitID) {
  118.         dataFile.getConfig().set("lastKitUsed", kitID);
  119.         refreshConfig();
  120.     }
  121.  
  122.     public String getLastKitUsed() {
  123.         return dataFile.getConfig().getString("lastKitUsed");
  124.     }
  125.  
  126.     public double getKDR() {
  127.         return (getKills() / getDeaths()) * 100;
  128.     }
  129.  
  130.     public double getArmorWorth() {
  131.         double armorworth = 0;
  132.  
  133.         if (player.getInventory().getHelmet().getType() == Material.LEATHER_HELMET) {
  134.             armorworth = armorworth + 0.5;
  135.         } else {
  136.             if (player.getInventory().getHelmet().getType() == Material.GOLD_HELMET || player.getInventory().getHelmet().getType() == Material.CHAINMAIL_HELMET || player.getInventory().getHelmet().getType() == Material.IRON_HELMET) {
  137.                 armorworth++;
  138.             } else {
  139.                 if (player.getInventory().getHelmet().getType() == Material.DIAMOND_HELMET) {
  140.                     armorworth = armorworth + 0.5;
  141.                 }
  142.             }
  143.         }
  144.  
  145.         if (player.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE) {
  146.             armorworth = armorworth + 1.5;
  147.         } else {
  148.             if (player.getInventory().getChestplate().getType() == Material.GOLD_CHESTPLATE || player.getInventory().getChestplate().getType() == Material.CHAINMAIL_CHESTPLATE) {
  149.                 armorworth = armorworth + 2.5;
  150.             } else {
  151.                 if (player.getInventory().getChestplate().getType() == Material.IRON_CHESTPLATE) {
  152.                     armorworth = armorworth + 3;
  153.                 } else {
  154.                     if (player.getInventory().getChestplate().getType() == Material.DIAMOND_CHESTPLATE) {
  155.                         armorworth = armorworth + 4;
  156.                     }
  157.                 }
  158.             }
  159.         }
  160.  
  161.         if (player.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS) {
  162.             armorworth++;
  163.         } else {
  164.             if (player.getInventory().getLeggings().getType() == Material.GOLD_LEGGINGS) {
  165.                 armorworth = armorworth + 1.5;
  166.             } else {
  167.                 if (player.getInventory().getLeggings().getType() == Material.CHAINMAIL_LEGGINGS) {
  168.                     armorworth = armorworth + 2;
  169.                 } else {
  170.                     if (player.getInventory().getLeggings().getType() == Material.IRON_LEGGINGS) {
  171.                         armorworth = armorworth + 2.5;
  172.                     } else {
  173.                         if (player.getInventory().getLeggings().getType() == Material.DIAMOND_LEGGINGS) {
  174.                             armorworth = armorworth + 3;
  175.                         }
  176.                     }
  177.                 }
  178.             }
  179.         }
  180.  
  181.         if (player.getInventory().getBoots().getType() == Material.LEATHER_BOOTS || player.getInventory().getBoots().getType() == Material.GOLD_BOOTS || player.getInventory().getBoots().getType() == Material.CHAINMAIL_BOOTS) {
  182.             armorworth = armorworth + 0.5;
  183.         } else {
  184.             if (player.getInventory().getBoots().getType() == Material.IRON_BOOTS) {
  185.                 armorworth++;
  186.             } else {
  187.                 if (player.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS) {
  188.                     armorworth = armorworth + 1.5;
  189.                 }
  190.             }
  191.         }
  192.  
  193.         return armorworth;
  194.     }
  195.  
  196.     public double getWorth() {
  197.         return (getCurrentKillStreak() * getKDR()) + (getArmorWorth());
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement