Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package me.insideintel.arena.API;
  2.  
  3. import org.bukkit.configuration.InvalidConfigurationException;
  4. import org.bukkit.configuration.file.FileConfiguration;
  5. import org.bukkit.configuration.file.YamlConfiguration;
  6. import org.bukkit.entity.Player;
  7.  
  8. import java.io.File;
  9. import java.io.IOException;
  10.  
  11. public class Economy {
  12. public static FileConfiguration GetEconomy(Player p) {
  13.  
  14. File user = GetUserData.GetPlayerFolder(p);
  15. FileConfiguration config = new YamlConfiguration();
  16. try {
  17. config.load(user);
  18. String money = config.getString("Money");
  19. if (money == null) {
  20. config.set("Money", 0.0);
  21. config.save(user);
  22. }
  23. } catch (IOException | InvalidConfigurationException ex) {
  24. System.out.println(ex);
  25. }
  26.  
  27. return config;
  28. }
  29.  
  30. public static void SaveMoney(Player p) {
  31.  
  32. }
  33.  
  34. public static void Add(Player p, double amount) {
  35. File user = GetUserData.GetPlayerFolder(p);
  36. FileConfiguration a = GetEconomy(p);
  37. try {
  38. a.load(user);
  39. a.set("Money", a.getDouble("Money") + amount);
  40. a.save(user);
  41. } catch (IOException | InvalidConfigurationException ex) {
  42.  
  43. }
  44. }
  45.  
  46. public static void Remove(Player p, double amount) {
  47. File user = GetUserData.GetPlayerFolder(p);
  48. FileConfiguration a = GetEconomy(p);
  49. try {
  50. a.load(user);
  51. if (Has(p, 0)) {
  52. if (Get(p) >= amount) {
  53. a.set("Money", a.getDouble("Money") - amount);
  54. a.save(user);
  55. }
  56. }
  57. } catch (IOException | InvalidConfigurationException ex) {
  58.  
  59. }
  60. }
  61.  
  62. public static void Set(Player p, double amount) {
  63. File user = GetUserData.GetPlayerFolder(p);
  64. FileConfiguration a = GetEconomy(p);
  65. try {
  66. a.load(user);
  67. a.set("Money", amount);
  68. a.save(user);
  69. } catch (IOException | InvalidConfigurationException ex) {
  70.  
  71. }
  72. }
  73.  
  74. public static boolean Has(Player p, double amount) {
  75. File user = GetUserData.GetPlayerFolder(p);
  76. FileConfiguration a = GetEconomy(p);
  77.  
  78. double money = a.getDouble("Money");
  79.  
  80. return money >= amount;
  81. }
  82.  
  83. public static double Get(Player p) {
  84. File user = GetUserData.GetPlayerFolder(p);
  85. FileConfiguration a = GetEconomy(p);
  86.  
  87. double money = a.getDouble("Money");
  88.  
  89. return money;
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement