|
| 1 | +package com.github.elic0de.thejpspit.hook; |
| 2 | + |
| 3 | +import com.github.elic0de.thejpspit.TheJpsPit; |
| 4 | +import com.github.elic0de.thejpspit.player.PitPlayer; |
| 5 | +import java.math.BigDecimal; |
| 6 | +import java.util.logging.Level; |
| 7 | +import net.tnemc.core.TNE; |
| 8 | +import net.tnemc.core.common.api.TNEAPI; |
| 9 | +import org.jetbrains.annotations.NotNull; |
| 10 | + |
| 11 | +public class TneEconomyHook extends EconomyHook { |
| 12 | + |
| 13 | + protected TNEAPI tneAPI; |
| 14 | + |
| 15 | + public TneEconomyHook(TheJpsPit plugin) { |
| 16 | + super(plugin, "TheNewEconomy"); |
| 17 | + } |
| 18 | + |
| 19 | + @Override |
| 20 | + public void onEnable() throws IllegalStateException { |
| 21 | + this.tneAPI = TNE.instance().api(); |
| 22 | + plugin.getLogger().log(Level.INFO, "Enabled Vault economy hook"); |
| 23 | + } |
| 24 | + |
| 25 | + private BigDecimal getBalance(@NotNull PitPlayer player) { |
| 26 | + return tneAPI.getAccount(player.getUniqueId()).getHoldings(player.getPlayer().getWorld().getName()); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public boolean hasMoney(PitPlayer player, BigDecimal amount) { |
| 31 | + return getBalance(player).compareTo(amount) >= 0; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public void takeMoney(PitPlayer player, BigDecimal amount) { |
| 36 | + tneAPI.getAccount(player.getUniqueId()).addHoldings(amount); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void giveMoney(PitPlayer player, BigDecimal amount) { |
| 41 | + tneAPI.getAccount(player.getUniqueId()).removeHoldings(amount); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public String formatMoney(BigDecimal amount) { |
| 46 | + return "tneAPI.format(amount.doubleValue(), world);"; |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments