EconomyManager.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package me.lethunderhawk.economy.currency;
  2. import me.lethunderhawk.economy.shop.ItemValues;
  3. import me.lethunderhawk.fluxapi.FluxService;
  4. import me.lethunderhawk.economy.EconomyModule;
  5. import org.bukkit.configuration.file.FileConfiguration;
  6. import java.util.UUID;
  7. public class EconomyManager {
  8. private final EconomyModule module;
  9. private final FileConfiguration config;
  10. private ItemValues itemValues;
  11. public EconomyManager() {
  12. this.module = FluxService.get(EconomyModule.class);
  13. this.config = module.getPlugin().getConfig();
  14. }
  15. public double getMoney(UUID uuid) {
  16. return config.getDouble("players." + uuid + ".money", 0);
  17. }
  18. public void setMoney(UUID uuid, double amount) {
  19. config.set("players." + uuid + ".money", amount);
  20. module.getPlugin().saveConfig();
  21. }
  22. public void addMoney(UUID uuid, double amount) {
  23. /*Player player = Bukkit.getPlayer(uuid);
  24. if(player != null) {
  25. player.sendMessage("§c" +EconomyUtil.stringFromNumber(amount) + "§e has been transferred into your account!");
  26. }*/
  27. setMoney(uuid, getMoney(uuid) + amount);
  28. }
  29. public boolean removeMoney(UUID uuid, double amount) {
  30. /*Player player = Bukkit.getPlayer(uuid);
  31. if(player != null) {
  32. player.sendMessage("§c" +EconomyUtil.stringFromNumber(amount) + "§e has been taken from your account!");
  33. }*/
  34. double newAmount = getMoney(uuid) - amount;
  35. if(newAmount < 0){
  36. return false;
  37. }
  38. setMoney(uuid, Math.max(0, newAmount));
  39. return true;
  40. }
  41. public long getTime() {
  42. return module.getPlugin().getServer().getWorld("world").getTime();
  43. }
  44. public void pay(UUID sender, UUID receiver, double amount) {
  45. if(amount > 0 && getMoney(sender) >= amount){
  46. removeMoney(sender, amount);
  47. addMoney(receiver, amount);
  48. }
  49. }
  50. public void setItemValues(ItemValues values) {
  51. this.itemValues = values;
  52. }
  53. public ItemValues getItemValues() {
  54. return itemValues;
  55. }
  56. }