package me.lethunderhawk.economy.currency; import me.lethunderhawk.economy.shop.ItemValues; import me.lethunderhawk.fluxapi.FluxService; import me.lethunderhawk.economy.EconomyModule; import org.bukkit.configuration.file.FileConfiguration; import java.util.UUID; public class EconomyManager { private final EconomyModule module; private final FileConfiguration config; private ItemValues itemValues; public EconomyManager() { this.module = FluxService.get(EconomyModule.class); this.config = module.getPlugin().getConfig(); } public double getMoney(UUID uuid) { return config.getDouble("players." + uuid + ".money", 0); } public void setMoney(UUID uuid, double amount) { config.set("players." + uuid + ".money", amount); module.getPlugin().saveConfig(); } public void addMoney(UUID uuid, double amount) { /*Player player = Bukkit.getPlayer(uuid); if(player != null) { player.sendMessage("§c" +EconomyUtil.stringFromNumber(amount) + "§e has been transferred into your account!"); }*/ setMoney(uuid, getMoney(uuid) + amount); } public boolean removeMoney(UUID uuid, double amount) { /*Player player = Bukkit.getPlayer(uuid); if(player != null) { player.sendMessage("§c" +EconomyUtil.stringFromNumber(amount) + "§e has been taken from your account!"); }*/ double newAmount = getMoney(uuid) - amount; if(newAmount < 0){ return false; } setMoney(uuid, Math.max(0, newAmount)); return true; } public long getTime() { return module.getPlugin().getServer().getWorld("world").getTime(); } public void pay(UUID sender, UUID receiver, double amount) { if(amount > 0 && getMoney(sender) >= amount){ removeMoney(sender, amount); addMoney(receiver, amount); } } public void setItemValues(ItemValues values) { this.itemValues = values; } public ItemValues getItemValues() { return itemValues; } }