diff --git a/build.gradle.kts b/build.gradle.kts index 0454ba7..0f2adc5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,7 +40,7 @@ allprojects { } dependencies { - compileOnly("com.willfp:eco:6.53.0") + compileOnly("com.willfp:eco:6.56.0") compileOnly("org.jetbrains:annotations:23.0.0") compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandBalance.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandBalance.kt index d994bbe..6f2446a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandBalance.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandBalance.kt @@ -5,13 +5,15 @@ import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.StringUtils import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.getBalance import org.bukkit.command.CommandSender import org.bukkit.entity.Player import org.bukkit.util.StringUtil class CommandBalance( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "balance", @@ -19,12 +21,14 @@ class CommandBalance( true ) { override fun onExecute(player: Player, args: List) { - if (args.isEmpty()) { - player.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.isEmpty()) { + player.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[0].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[0].lowercase()) if (currency == null) { player.sendMessage(plugin.langYml.getMessage("invalid-currency")) @@ -41,16 +45,18 @@ class CommandBalance( override fun tabComplete(sender: CommandSender, args: List): List { val completions = mutableListOf() - if (args.isEmpty()) { - Currencies.values().map { it.id } - } + if (this.currency == null) { + if (args.isEmpty()) { + Currencies.values().map { it.id } + } - if (args.size == 1) { - StringUtil.copyPartialMatches( - args[0], - Currencies.values().map { it.id }, - completions - ) + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Currencies.values().map { it.id }, + completions + ) + } } return completions diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGet.kt index 835e234..1d02e0c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGet.kt @@ -6,13 +6,15 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.getBalance import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandGet( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "get", @@ -33,12 +35,14 @@ class CommandGet( return } - if (args.size < 2) { - sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-currency")) @@ -68,12 +72,14 @@ class CommandGet( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } return completions diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGive.kt index 813a9c2..cee3a01 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGive.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGive.kt @@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandGive( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "give", "ecobits.command.give", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { sender.sendMessage(plugin.langYml.getMessage("must-specify-player")) @@ -33,24 +37,26 @@ class CommandGive( return } - if (args.size < 2) { - sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-currency")) return } - if (args.size < 3) { + if (args.size < 3 + argOffset) { sender.sendMessage(plugin.langYml.getMessage("must-specify-amount")) return } - val amount = args[2].toDoubleOrNull() + val amount = args[2 + argOffset].toDoubleOrNull() if (amount == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) @@ -82,17 +88,19 @@ class CommandGive( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGivesilent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGivesilent.kt index e930280..d63e324 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGivesilent.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandGivesilent.kt @@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandGivesilent( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "givesilent", "ecobits.command.givesilent", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { return @@ -31,17 +35,19 @@ class CommandGivesilent( return } - if (args.size < 2) { + if (this.currency == null) { + if (args.size < 2) { + return + } + } + + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) ?: return + + if (args.size < 3 + argOffset) { return } - val currency = Currencies.getByID(args[1].lowercase()) ?: return - - if (args.size < 3) { - return - } - - val amount = args[2].toDoubleOrNull() ?: return + val amount = args[2 + argOffset].toDoubleOrNull() ?: return player.adjustBalance(currency, amount) } @@ -61,17 +67,19 @@ class CommandGivesilent( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandPay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandPay.kt index cc44486..6f6958d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandPay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandPay.kt @@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import com.willfp.ecobits.currencies.getBalance import org.bukkit.Bukkit @@ -16,13 +17,16 @@ import kotlin.math.ceil import kotlin.math.floor class CommandPay( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "pay", "ecobits.command.pay", true ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(player: Player, args: List) { if (args.isEmpty()) { player.sendMessage(plugin.langYml.getMessage("must-specify-player")) @@ -37,24 +41,26 @@ class CommandPay( return } - if (args.size < 2) { - player.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + player.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null || !currency.isPayable) { player.sendMessage(plugin.langYml.getMessage("invalid-currency")) return } - if (args.size < 3) { + if (args.size < 3 + argOffset) { player.sendMessage(plugin.langYml.getMessage("must-specify-amount")) return } - val amount = args[2].toDoubleOrNull() + val amount = args[2 + argOffset].toDoubleOrNull() if (amount == null || amount <= 0) { player.sendMessage(plugin.langYml.getMessage("invalid-amount")) @@ -102,17 +108,19 @@ class CommandPay( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().filter { it.isPayable }.map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().filter { it.isPayable }.map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandReset.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandReset.kt index acd5fb8..3109a24 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandReset.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandReset.kt @@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.getBalance import com.willfp.ecobits.currencies.setBalance import org.bukkit.Bukkit @@ -13,13 +14,16 @@ import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandReset( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "reset", "ecobits.command.reset", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { sender.sendMessage(plugin.langYml.getMessage("must-specify-player")) @@ -34,12 +38,14 @@ class CommandReset( return } - if (args.size < 2) { - sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-currency")) @@ -71,12 +77,14 @@ class CommandReset( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } return completions diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandSet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandSet.kt index ba939a4..4c0947d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandSet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandSet.kt @@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import com.willfp.ecobits.currencies.setBalance import org.bukkit.Bukkit @@ -13,13 +14,16 @@ import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandSet( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "set", "ecobits.command.set", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { sender.sendMessage(plugin.langYml.getMessage("must-specify-player")) @@ -34,24 +38,26 @@ class CommandSet( return } - if (args.size < 2) { - sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-currency")) return } - if (args.size < 3) { + if (args.size < 3 + argOffset) { sender.sendMessage(plugin.langYml.getMessage("must-specify-amount")) return } - val amount = args[2].toDoubleOrNull() + val amount = args[2 + argOffset].toDoubleOrNull() if (amount == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) @@ -83,17 +89,19 @@ class CommandSet( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTake.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTake.kt index de7fad3..e45c239 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTake.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTake.kt @@ -7,19 +7,23 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandTake( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "take", "ecobits.command.take", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { sender.sendMessage(plugin.langYml.getMessage("must-specify-player")) @@ -34,24 +38,26 @@ class CommandTake( return } - if (args.size < 2) { - sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) - return + if (this.currency == null) { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("must-specify-currency")) + return + } } - val currency = Currencies.getByID(args[1].lowercase()) + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) if (currency == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-currency")) return } - if (args.size < 3) { + if (args.size < 3 + argOffset) { sender.sendMessage(plugin.langYml.getMessage("must-specify-amount")) return } - val amount = args[2].toDoubleOrNull() + val amount = args[2 + argOffset].toDoubleOrNull() if (amount == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) @@ -83,17 +89,19 @@ class CommandTake( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTakesilent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTakesilent.kt index 0afd002..c225e5f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTakesilent.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/CommandTakesilent.kt @@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.toNiceString import com.willfp.ecobits.currencies.Currencies +import com.willfp.ecobits.currencies.Currency import com.willfp.ecobits.currencies.adjustBalance import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandTakesilent( - plugin: EcoPlugin + plugin: EcoPlugin, + private val currency: Currency? = null ) : Subcommand( plugin, "takesilent", "ecobits.command.takesilent", false ) { + private val argOffset = if (currency == null) 0 else -1 + override fun onExecute(sender: CommandSender, args: List) { if (args.isEmpty()) { return @@ -31,17 +35,19 @@ class CommandTakesilent( return } - if (args.size < 2) { + if (this.currency == null) { + if (args.size < 2) { + return + } + } + + val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) ?: return + + if (args.size < 3 + argOffset) { return } - val currency = Currencies.getByID(args[1].lowercase()) ?: return - - if (args.size < 3) { - return - } - - val amount = args[2].toDoubleOrNull() ?: return + val amount = args[2 + argOffset].toDoubleOrNull() ?: return player.adjustBalance(currency, -amount) } @@ -61,17 +67,19 @@ class CommandTakesilent( ) } - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Currencies.values().map { it.id }, - completions - ) + if (this.currency == null) { + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Currencies.values().map { it.id }, + completions + ) + } } - if (args.size == 3) { + if (args.size == 3 + argOffset) { StringUtil.copyPartialMatches( - args[2], + args[2 + argOffset], arrayOf(1, 2, 3, 4, 5).map { it.toString() }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/DynamicCurrencyCommand.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/DynamicCurrencyCommand.kt index bdc9f0b..4c63c98 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/DynamicCurrencyCommand.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/commands/DynamicCurrencyCommand.kt @@ -15,89 +15,27 @@ class DynamicCurrencyCommand( plugin: EcoPlugin, label: String, val currency: Currency -): PluginCommand( +) : PluginCommand( plugin, label, "ecobits.command.${currency.id}", false ) { init { - DynamicCurrencySubcommand.allCommands.forEach { - this.addSubcommand( - DynamicCurrencySubcommand(plugin, it, currency) - ) - } + this.addSubcommand(CommandGive(plugin, currency)) + .addSubcommand(CommandGivesilent(plugin, currency)) + .addSubcommand(CommandGet(plugin, currency)) + .addSubcommand(CommandSet(plugin, currency)) + .addSubcommand(CommandReset(plugin, currency)) + .addSubcommand(CommandPay(plugin, currency)) + .addSubcommand(CommandBalance(plugin, currency)) + .addSubcommand(CommandTake(plugin, currency)) + .addSubcommand(CommandTakesilent(plugin, currency)) } override fun onExecute(sender: CommandSender, args: MutableList) { - sender.sendMessage(this.plugin.langYml.getMessage("invalid-command")) + sender.sendMessage( + plugin.langYml.getMessage("invalid-command") + ) } - - - class DynamicCurrencySubcommand( - plugin: EcoPlugin, - val command: String, - val currency: Currency - ): Subcommand( - plugin, - command, - "ecobits.command.${currency.id}.$command", - false - ) { - override fun onExecute(sender: CommandSender, args: MutableList) { - super.onExecute(sender, args) - } - - override fun onExecute(sender: Player, args: MutableList) { - val format = when { - currencyCommands.containsIgnoreCase(command) -> currencyFormat - playerCurrencyCommands.containsIgnoreCase(command) -> playerCurrencyFormat - playerCurrencyAmountCommands.containsIgnoreCase(command) -> playerCurrencyAmountFormat - else -> "" - } - - Bukkit.dispatchCommand(sender, - format.replace( - "%command%", command - ).replace( - "%player%", args.getOrElse(0) { "" } - ).replace( - "%amount%", args.getOrElse(1) { "" } - ).replace( - "%currency%", currency.id - ) - ) - } - - override fun tabComplete(sender: CommandSender, args: MutableList): MutableList { - return when { - args.size == 1 -> { - if (currencyCommands.containsIgnoreCase(command)) { - StringUtil.copyPartialMatches(args.first(), - Currencies.values().map { it.id }, mutableListOf()) - } else { - StringUtil.copyPartialMatches(args.first(), - Bukkit.getOnlinePlayers().map { it.name }, mutableListOf()) - } - } - - args.size == 2 && !currencyCommands.containsIgnoreCase(command) -> { - StringUtil.copyPartialMatches(args.first(), - Currencies.values().map { it.id }, mutableListOf()) - } - - else -> mutableListOf() - } - } - - companion object { - val currencyCommands = listOf("balance") - val playerCurrencyCommands = listOf("get", "reset") - val playerCurrencyAmountCommands = listOf("give", "givesilent", "pay", "set", "take", "takesilent") - val allCommands = currencyCommands + playerCurrencyCommands + playerCurrencyAmountCommands - val currencyFormat = "ecobits %command% %currency%" - val playerCurrencyFormat = "ecobits %command% %player% %currency%" - val playerCurrencyAmountFormat = "ecobits %command% %player% %currency% %amount%" - } - } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/Currency.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/Currency.kt index e995d6a..8b9554c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/Currency.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/Currency.kt @@ -71,14 +71,11 @@ class Currency( }.orElse(null) } - fun registerCommands() { - this.commands.forEach { - println("Registered ${it.name}") - it.register() - } + private fun registerCommands() { + this.commands.forEach { it.register() } } - fun unregisterCommands() { + private fun unregisterCommands() { this.commands.forEach { it.unregister() } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/PriceFactoryCurrency.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/PriceFactoryCurrency.kt index c11240b..d3649db 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/PriceFactoryCurrency.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobits/currencies/PriceFactoryCurrency.kt @@ -1,6 +1,8 @@ package com.willfp.ecobits.currencies import com.willfp.eco.core.math.MathContext +import com.willfp.eco.core.placeholder.context.PlaceholderContext +import com.willfp.eco.core.placeholder.context.PlaceholderContextSupplier import com.willfp.eco.core.price.Price import com.willfp.eco.core.price.PriceFactory import org.bukkit.entity.Player @@ -14,14 +16,14 @@ class PriceFactoryCurrency( currency.id ) - override fun create(baseContext: MathContext, function: Function): Price { - return PriceCurrency(currency, baseContext) { function.apply(it) } + override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier): Price { + return PriceCurrency(currency, baseContext) { function.get(it) } } private class PriceCurrency( private val currency: Currency, - private val baseContext: MathContext, - private val xp: (MathContext) -> Double + private val baseContext: PlaceholderContext, + private val xp: (PlaceholderContext) -> Double ) : Price { private val multipliers = mutableMapOf() @@ -35,7 +37,7 @@ class PriceFactoryCurrency( player.adjustBalance(currency, getValue(player, multiplier)) override fun getValue(player: Player, multiplier: Double) = - xp(MathContext.copyWithPlayer(baseContext, player)) * getMultiplier(player) * multiplier + xp(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier override fun getMultiplier(player: Player): Double { return multipliers[player.uniqueId] ?: 1.0 @@ -45,4 +47,4 @@ class PriceFactoryCurrency( multipliers[player.uniqueId] = multiplier } } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 5583e51..453a0ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.5.0 +version = 1.6.0 plugin-name = EcoBits