mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
monetary dependency functions
This commit is contained in:
parent
856c1e08bd
commit
1660250ee1
4 changed files with 64 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
|
|||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import java.util.*
|
||||
|
|
@ -640,9 +641,10 @@ object ConfigOptions {
|
|||
*/
|
||||
val shouldUseMoney: Boolean
|
||||
get() {
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(SHOULD_USE_MONEY, DEFAULT_SHOULD_USE_MONEY)
|
||||
return EconomyManager.economy?.initialized() == true &&
|
||||
ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(SHOULD_USE_MONEY, DEFAULT_SHOULD_USE_MONEY)
|
||||
}
|
||||
|
||||
val usedCurrency: String
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.economy
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.math.BigDecimal
|
||||
|
||||
interface EconomyManager {
|
||||
|
||||
|
|
@ -21,7 +23,10 @@ interface EconomyManager {
|
|||
|
||||
fun initialized(): Boolean
|
||||
|
||||
// We assume "initialized" got checked before these function get called
|
||||
fun has(player: Player, money: BigDecimal): Boolean
|
||||
fun remove(player: Player, money: BigDecimal): Boolean
|
||||
|
||||
|
||||
fun format(money: BigDecimal): String;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.economy
|
||||
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import net.milkbowl.vault2.economy.Economy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.math.BigDecimal
|
||||
|
||||
class UnlockedEconomyManager: EconomyManager {
|
||||
|
||||
|
|
@ -30,6 +33,38 @@ class UnlockedEconomyManager: EconomyManager {
|
|||
return economy != null
|
||||
}
|
||||
|
||||
private fun currency(): String {
|
||||
val configured = ConfigOptions.usedCurrency
|
||||
|
||||
return if ("default".equals(configured, true))
|
||||
economy!!.getDefaultCurrency(plugin)
|
||||
else configured
|
||||
}
|
||||
|
||||
override fun has(player: Player, money: BigDecimal): Boolean {
|
||||
if(money.signum() <= 0) return true
|
||||
|
||||
return economy!!.has(plugin,
|
||||
player.uniqueId,
|
||||
player.world.name,
|
||||
currency(),
|
||||
money)
|
||||
}
|
||||
|
||||
override fun remove(player: Player, money: BigDecimal): Boolean {
|
||||
if(money.signum() <= 0) return true
|
||||
|
||||
return economy!!.withdraw(plugin,
|
||||
player.uniqueId,
|
||||
player.world.name,
|
||||
currency(),
|
||||
money)
|
||||
.transactionSuccess()
|
||||
}
|
||||
|
||||
override fun format(money: BigDecimal): String {
|
||||
return economy!!.format(plugin, money, currency())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.economy
|
||||
|
||||
import net.milkbowl.vault.economy.Economy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.math.BigDecimal
|
||||
|
||||
class VaultEconomyManager : EconomyManager {
|
||||
|
||||
val economy: Economy?
|
||||
|
|
@ -15,5 +18,20 @@ class VaultEconomyManager : EconomyManager {
|
|||
return economy != null
|
||||
}
|
||||
|
||||
override fun has(player: Player, money: BigDecimal): Boolean {
|
||||
if(money.signum() <= 0) return true
|
||||
|
||||
return economy!!.has(player, money.toDouble())
|
||||
}
|
||||
|
||||
override fun remove(player: Player, money: BigDecimal): Boolean {
|
||||
if(money.signum() <= 0) return true
|
||||
|
||||
return economy!!.withdrawPlayer(player, money.toDouble()).transactionSuccess()
|
||||
}
|
||||
|
||||
override fun format(money: BigDecimal): String {
|
||||
return economy!!.format(money.toDouble())
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue