mirror of
https://github.com/Auxilor/EcoBits.git
synced 2025-12-19 15:09:19 +00:00
Merge branch 'leaderboard'
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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<String>) {
|
||||
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,6 +45,7 @@ class CommandBalance(
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.isEmpty()) {
|
||||
Currencies.values().map { it.id }
|
||||
}
|
||||
@@ -52,6 +57,7 @@ class CommandBalance(
|
||||
completions
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return completions
|
||||
}
|
||||
|
||||
@@ -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 (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,6 +72,7 @@ class CommandGet(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -75,6 +80,7 @@ class CommandGet(
|
||||
completions
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return completions
|
||||
}
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||
@@ -33,24 +37,26 @@ class CommandGive(
|
||||
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,6 +88,7 @@ class CommandGive(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -89,10 +96,11 @@ class CommandGive(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
return
|
||||
@@ -31,17 +35,19 @@ class CommandGivesilent(
|
||||
return
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size < 2) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val currency = Currencies.getByID(args[1].lowercase()) ?: return
|
||||
val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) ?: return
|
||||
|
||||
if (args.size < 3) {
|
||||
if (args.size < 3 + argOffset) {
|
||||
return
|
||||
}
|
||||
|
||||
val amount = args[2].toDoubleOrNull() ?: return
|
||||
val amount = args[2 + argOffset].toDoubleOrNull() ?: return
|
||||
|
||||
player.adjustBalance(currency, amount)
|
||||
}
|
||||
@@ -61,6 +67,7 @@ class CommandGivesilent(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -68,10 +75,11 @@ class CommandGivesilent(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
player.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||
@@ -37,24 +41,26 @@ class CommandPay(
|
||||
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,6 +108,7 @@ class CommandPay(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -109,10 +116,11 @@ class CommandPay(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||
@@ -34,12 +38,14 @@ class CommandReset(
|
||||
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,6 +77,7 @@ class CommandReset(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -78,6 +85,7 @@ class CommandReset(
|
||||
completions
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return completions
|
||||
}
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||
@@ -34,24 +38,26 @@ class CommandSet(
|
||||
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,6 +89,7 @@ class CommandSet(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -90,10 +97,11 @@ class CommandSet(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||
@@ -34,24 +38,26 @@ class CommandTake(
|
||||
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,6 +89,7 @@ class CommandTake(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -90,10 +97,11 @@ class CommandTake(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
if (args.isEmpty()) {
|
||||
return
|
||||
@@ -31,17 +35,19 @@ class CommandTakesilent(
|
||||
return
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size < 2) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val currency = Currencies.getByID(args[1].lowercase()) ?: return
|
||||
val currency = this.currency ?: Currencies.getByID(args[1].lowercase()) ?: return
|
||||
|
||||
if (args.size < 3) {
|
||||
if (args.size < 3 + argOffset) {
|
||||
return
|
||||
}
|
||||
|
||||
val amount = args[2].toDoubleOrNull() ?: return
|
||||
val amount = args[2 + argOffset].toDoubleOrNull() ?: return
|
||||
|
||||
player.adjustBalance(currency, -amount)
|
||||
}
|
||||
@@ -61,6 +67,7 @@ class CommandTakesilent(
|
||||
)
|
||||
}
|
||||
|
||||
if (this.currency == null) {
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
@@ -68,10 +75,11 @@ class CommandTakesilent(
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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<String>) {
|
||||
sender.sendMessage(this.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<String>) {
|
||||
super.onExecute(sender, args)
|
||||
}
|
||||
|
||||
override fun onExecute(sender: Player, args: MutableList<String>) {
|
||||
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
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("invalid-command")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun tabComplete(sender: CommandSender, args: MutableList<String>): MutableList<String> {
|
||||
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%"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() }
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MathContext, Double>): Price {
|
||||
return PriceCurrency(currency, baseContext) { function.apply(it) }
|
||||
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): 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<UUID, Double>()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 1.5.0
|
||||
version = 1.6.0
|
||||
plugin-name = EcoBits
|
||||
|
||||
Reference in New Issue
Block a user