9
0
mirror of https://github.com/Auxilor/EcoBits.git synced 2026-01-06 15:52:04 +00:00

Added /ecobits takesilent

This commit is contained in:
Auxilor
2022-11-21 20:36:34 +00:00
parent a12a955f4e
commit 09c066b4a1
3 changed files with 87 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ class CommandEcoBits(plugin: EcoPlugin) : PluginCommand(plugin, "ecobits", "ecob
.addSubcommand(CommandPay(plugin))
.addSubcommand(CommandBalance(plugin))
.addSubcommand(CommandTake(plugin))
.addSubcommand(CommandTakesilent(plugin))
}
override fun onExecute(sender: CommandSender, args: List<String>) {

View File

@@ -0,0 +1,82 @@
package com.willfp.ecobits.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.Subcommand
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.adjustBalance
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import org.bukkit.util.StringUtil
class CommandTakesilent(
plugin: EcoPlugin
) : Subcommand(
plugin,
"takesilent",
"ecobits.command.takesilent",
false
) {
override fun onExecute(sender: CommandSender, args: List<String>) {
if (args.isEmpty()) {
return
}
@Suppress("DEPRECATION")
val player = Bukkit.getOfflinePlayer(args[0])
if (!player.hasPlayedBefore() && !player.isOnline) {
return
}
if (args.size < 2) {
return
}
val currency = Currencies.getByID(args[1].lowercase()) ?: return
if (args.size < 3) {
return
}
val amount = args[2].toDoubleOrNull() ?: return
player.adjustBalance(currency, -amount)
}
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
val completions = mutableListOf<String>()
if (args.isEmpty()) {
return Bukkit.getOnlinePlayers().map { it.name }
}
if (args.size == 1) {
StringUtil.copyPartialMatches(
args[0],
Bukkit.getOnlinePlayers().map { it.name },
completions
)
}
if (args.size == 2) {
StringUtil.copyPartialMatches(
args[1],
Currencies.values().map { it.id },
completions
)
}
if (args.size == 3) {
StringUtil.copyPartialMatches(
args[2],
arrayOf(1, 2, 3, 4, 5).map { it.toString() },
completions
)
}
return completions
}
}

View File

@@ -33,6 +33,7 @@ permissions:
ecobits.command.reset: true
ecobits.command.pay: true
ecobits.command.take: true
ecobits.command.takesilent: true
ecobits.command.balance: true
ecobits.command.reload:
@@ -44,6 +45,9 @@ permissions:
ecobits.command.take:
description: Takes a currency
default: op
ecobits.command.takesilent:
description: Takes a currency silently
default: op
ecobits.command.givesilent:
description: Gives a currency silently
default: op