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 {
|
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:annotations:23.0.0")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
|
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.StringUtils
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.getBalance
|
import com.willfp.ecobits.currencies.getBalance
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandBalance(
|
class CommandBalance(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"balance",
|
"balance",
|
||||||
@@ -19,12 +21,14 @@ class CommandBalance(
|
|||||||
true
|
true
|
||||||
) {
|
) {
|
||||||
override fun onExecute(player: Player, args: List<String>) {
|
override fun onExecute(player: Player, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (this.currency == null) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.isEmpty()) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
player.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
@@ -41,16 +45,18 @@ class CommandBalance(
|
|||||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||||
val completions = mutableListOf<String>()
|
val completions = mutableListOf<String>()
|
||||||
|
|
||||||
if (args.isEmpty()) {
|
if (this.currency == null) {
|
||||||
Currencies.values().map { it.id }
|
if (args.isEmpty()) {
|
||||||
}
|
Currencies.values().map { it.id }
|
||||||
|
}
|
||||||
|
|
||||||
if (args.size == 1) {
|
if (args.size == 1) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[0],
|
args[0],
|
||||||
Currencies.values().map { it.id },
|
Currencies.values().map { it.id },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions
|
return completions
|
||||||
|
|||||||
@@ -6,13 +6,15 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.getBalance
|
import com.willfp.ecobits.currencies.getBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandGet(
|
class CommandGet(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"get",
|
"get",
|
||||||
@@ -33,12 +35,14 @@ class CommandGet(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
@@ -68,12 +72,14 @@ class CommandGet(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions
|
return completions
|
||||||
|
|||||||
@@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandGive(
|
class CommandGive(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"give",
|
"give",
|
||||||
"ecobits.command.give",
|
"ecobits.command.give",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||||
@@ -33,24 +37,26 @@ class CommandGive(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 3) {
|
if (args.size < 3 + argOffset) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull()
|
val amount = args[2 + argOffset].toDoubleOrNull()
|
||||||
|
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||||
@@ -82,17 +88,19 @@ class CommandGive(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandGivesilent(
|
class CommandGivesilent(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"givesilent",
|
"givesilent",
|
||||||
"ecobits.command.givesilent",
|
"ecobits.command.givesilent",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
return
|
return
|
||||||
@@ -31,17 +35,19 @@ class CommandGivesilent(
|
|||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val currency = Currencies.getByID(args[1].lowercase()) ?: return
|
val amount = args[2 + argOffset].toDoubleOrNull() ?: return
|
||||||
|
|
||||||
if (args.size < 3) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull() ?: return
|
|
||||||
|
|
||||||
player.adjustBalance(currency, amount)
|
player.adjustBalance(currency, amount)
|
||||||
}
|
}
|
||||||
@@ -61,17 +67,19 @@ class CommandGivesilent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import com.willfp.ecobits.currencies.getBalance
|
import com.willfp.ecobits.currencies.getBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
@@ -16,13 +17,16 @@ import kotlin.math.ceil
|
|||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
class CommandPay(
|
class CommandPay(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"pay",
|
"pay",
|
||||||
"ecobits.command.pay",
|
"ecobits.command.pay",
|
||||||
true
|
true
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(player: Player, args: List<String>) {
|
override fun onExecute(player: Player, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
player.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||||
@@ -37,24 +41,26 @@ class CommandPay(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null || !currency.isPayable) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
player.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 3) {
|
if (args.size < 3 + argOffset) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
player.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull()
|
val amount = args[2 + argOffset].toDoubleOrNull()
|
||||||
|
|
||||||
if (amount == null || amount <= 0) {
|
if (amount == null || amount <= 0) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
player.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||||
@@ -102,17 +108,19 @@ class CommandPay(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().filter { it.isPayable }.map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().filter { it.isPayable }.map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.getBalance
|
import com.willfp.ecobits.currencies.getBalance
|
||||||
import com.willfp.ecobits.currencies.setBalance
|
import com.willfp.ecobits.currencies.setBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
@@ -13,13 +14,16 @@ import org.bukkit.command.CommandSender
|
|||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandReset(
|
class CommandReset(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"reset",
|
"reset",
|
||||||
"ecobits.command.reset",
|
"ecobits.command.reset",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||||
@@ -34,12 +38,14 @@ class CommandReset(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
@@ -71,12 +77,14 @@ class CommandReset(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions
|
return completions
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import com.willfp.ecobits.currencies.setBalance
|
import com.willfp.ecobits.currencies.setBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
@@ -13,13 +14,16 @@ import org.bukkit.command.CommandSender
|
|||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandSet(
|
class CommandSet(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"set",
|
"set",
|
||||||
"ecobits.command.set",
|
"ecobits.command.set",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||||
@@ -34,24 +38,26 @@ class CommandSet(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 3) {
|
if (args.size < 3 + argOffset) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull()
|
val amount = args[2 + argOffset].toDoubleOrNull()
|
||||||
|
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||||
@@ -83,17 +89,19 @@ class CommandSet(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,19 +7,23 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandTake(
|
class CommandTake(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"take",
|
"take",
|
||||||
"ecobits.command.take",
|
"ecobits.command.take",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-player"))
|
||||||
@@ -34,24 +38,26 @@ class CommandTake(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 2) {
|
if (this.currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-currency"))
|
if (args.size < 2) {
|
||||||
return
|
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) {
|
if (currency == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-currency"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size < 3) {
|
if (args.size < 3 + argOffset) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("must-specify-amount"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull()
|
val amount = args[2 + argOffset].toDoubleOrNull()
|
||||||
|
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||||
@@ -83,17 +89,19 @@ class CommandTake(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,19 +6,23 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.savedDisplayName
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.eco.util.toNiceString
|
import com.willfp.eco.util.toNiceString
|
||||||
import com.willfp.ecobits.currencies.Currencies
|
import com.willfp.ecobits.currencies.Currencies
|
||||||
|
import com.willfp.ecobits.currencies.Currency
|
||||||
import com.willfp.ecobits.currencies.adjustBalance
|
import com.willfp.ecobits.currencies.adjustBalance
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.util.StringUtil
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
class CommandTakesilent(
|
class CommandTakesilent(
|
||||||
plugin: EcoPlugin
|
plugin: EcoPlugin,
|
||||||
|
private val currency: Currency? = null
|
||||||
) : Subcommand(
|
) : Subcommand(
|
||||||
plugin,
|
plugin,
|
||||||
"takesilent",
|
"takesilent",
|
||||||
"ecobits.command.takesilent",
|
"ecobits.command.takesilent",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
|
private val argOffset = if (currency == null) 0 else -1
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
return
|
return
|
||||||
@@ -31,17 +35,19 @@ class CommandTakesilent(
|
|||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val currency = Currencies.getByID(args[1].lowercase()) ?: return
|
val amount = args[2 + argOffset].toDoubleOrNull() ?: return
|
||||||
|
|
||||||
if (args.size < 3) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val amount = args[2].toDoubleOrNull() ?: return
|
|
||||||
|
|
||||||
player.adjustBalance(currency, -amount)
|
player.adjustBalance(currency, -amount)
|
||||||
}
|
}
|
||||||
@@ -61,17 +67,19 @@ class CommandTakesilent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 2) {
|
if (this.currency == null) {
|
||||||
StringUtil.copyPartialMatches(
|
if (args.size == 2) {
|
||||||
args[1],
|
StringUtil.copyPartialMatches(
|
||||||
Currencies.values().map { it.id },
|
args[1],
|
||||||
completions
|
Currencies.values().map { it.id },
|
||||||
)
|
completions
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size == 3) {
|
if (args.size == 3 + argOffset) {
|
||||||
StringUtil.copyPartialMatches(
|
StringUtil.copyPartialMatches(
|
||||||
args[2],
|
args[2 + argOffset],
|
||||||
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
|
||||||
completions
|
completions
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,89 +15,27 @@ class DynamicCurrencyCommand(
|
|||||||
plugin: EcoPlugin,
|
plugin: EcoPlugin,
|
||||||
label: String,
|
label: String,
|
||||||
val currency: Currency
|
val currency: Currency
|
||||||
): PluginCommand(
|
) : PluginCommand(
|
||||||
plugin,
|
plugin,
|
||||||
label,
|
label,
|
||||||
"ecobits.command.${currency.id}",
|
"ecobits.command.${currency.id}",
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
DynamicCurrencySubcommand.allCommands.forEach {
|
this.addSubcommand(CommandGive(plugin, currency))
|
||||||
this.addSubcommand(
|
.addSubcommand(CommandGivesilent(plugin, currency))
|
||||||
DynamicCurrencySubcommand(plugin, it, 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>) {
|
override fun onExecute(sender: CommandSender, args: MutableList<String>) {
|
||||||
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<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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
}.orElse(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerCommands() {
|
private fun registerCommands() {
|
||||||
this.commands.forEach {
|
this.commands.forEach { it.register() }
|
||||||
println("Registered ${it.name}")
|
|
||||||
it.register()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unregisterCommands() {
|
private fun unregisterCommands() {
|
||||||
this.commands.forEach { it.unregister() }
|
this.commands.forEach { it.unregister() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.willfp.ecobits.currencies
|
package com.willfp.ecobits.currencies
|
||||||
|
|
||||||
import com.willfp.eco.core.math.MathContext
|
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.Price
|
||||||
import com.willfp.eco.core.price.PriceFactory
|
import com.willfp.eco.core.price.PriceFactory
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@@ -14,14 +16,14 @@ class PriceFactoryCurrency(
|
|||||||
currency.id
|
currency.id
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun create(baseContext: MathContext, function: Function<MathContext, Double>): Price {
|
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): Price {
|
||||||
return PriceCurrency(currency, baseContext) { function.apply(it) }
|
return PriceCurrency(currency, baseContext) { function.get(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PriceCurrency(
|
private class PriceCurrency(
|
||||||
private val currency: Currency,
|
private val currency: Currency,
|
||||||
private val baseContext: MathContext,
|
private val baseContext: PlaceholderContext,
|
||||||
private val xp: (MathContext) -> Double
|
private val xp: (PlaceholderContext) -> Double
|
||||||
) : Price {
|
) : Price {
|
||||||
private val multipliers = mutableMapOf<UUID, Double>()
|
private val multipliers = mutableMapOf<UUID, Double>()
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ class PriceFactoryCurrency(
|
|||||||
player.adjustBalance(currency, getValue(player, multiplier))
|
player.adjustBalance(currency, getValue(player, multiplier))
|
||||||
|
|
||||||
override fun getValue(player: Player, multiplier: Double) =
|
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 {
|
override fun getMultiplier(player: Player): Double {
|
||||||
return multipliers[player.uniqueId] ?: 1.0
|
return multipliers[player.uniqueId] ?: 1.0
|
||||||
@@ -45,4 +47,4 @@ class PriceFactoryCurrency(
|
|||||||
multipliers[player.uniqueId] = multiplier
|
multipliers[player.uniqueId] = multiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 1.5.0
|
version = 1.6.0
|
||||||
plugin-name = EcoBits
|
plugin-name = EcoBits
|
||||||
|
|||||||
Reference in New Issue
Block a user