Withdraw money

This commit is contained in:
2025-02-03 12:46:37 +08:00
parent d89cd6f9ce
commit 582c0c45b2
3 changed files with 131 additions and 3 deletions

View File

@@ -2,9 +2,11 @@ package dev.solsynth.snConnect.commands
import dev.solsynth.snConnect.services.SnOrderService
import dev.solsynth.snConnect.services.SnService
import dev.solsynth.snConnect.services.SnTransactionService
import net.md_5.bungee.api.chat.ClickEvent
import net.md_5.bungee.api.chat.TextComponent
import net.milkbowl.vault.economy.Economy
import net.milkbowl.vault.economy.EconomyResponse
import org.bukkit.ChatColor
import org.bukkit.Sound
import org.bukkit.command.Command
@@ -44,8 +46,9 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
eco?.depositPlayer(p0.player, bal)
val doneComponent = TextComponent(ChatColor.GREEN.toString() + "Done!")
val moneyComponent = TextComponent(ChatColor.GOLD.toString()+ChatColor.BOLD + " $bal$")
val suffixComponent = TextComponent(ChatColor.GREEN.toString() +" has been added to your balance.")
val moneyComponent = TextComponent(ChatColor.GOLD.toString() + ChatColor.BOLD + " $bal$")
val suffixComponent =
TextComponent(ChatColor.GREEN.toString() + " has been added to your balance.")
p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
p0.spigot().sendMessage(doneComponent, moneyComponent, suffixComponent)
@@ -81,6 +84,48 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
p0.spigot().sendMessage(afterPaidComponent);
}
"withdraw" -> {
if (p3.size < 2) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific an amount to deposit.")
return true;
}
val amount = p3[1].toDoubleOrNull();
if (amount == null) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific an amount of number to deposit.")
return true;
}
if (p3.size < 3) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific a wallet account to deposit.")
return true;
}
val walletId = p3[2].toLongOrNull();
if (walletId == null) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific a wallet account to deposit.")
return true;
}
p0.sendMessage(ChatColor.GRAY.toString() + "Making transaction, please stand by...");
val bal = amount / 100;
val resp = eco?.withdrawPlayer(p0.player, "Withdraw to Source Point - $bal SRC", amount);
if (resp?.type != EconomyResponse.ResponseType.SUCCESS) {
p0.sendMessage(ChatColor.RED.toString() + "Your in game account has no enough money for that.")
return true;
}
val transactionSrv = SnTransactionService(sn);
val transaction = transactionSrv.makeTransaction(bal, "Withdraw from Highland MC", walletId);
val transactionHintComponent =
TextComponent(ChatColor.GREEN.toString() + "Done! transaction number " + ChatColor.WHITE + ChatColor.BOLD + "#${transaction.id}")
p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
p0.spigot().sendMessage(transactionHintComponent)
}
else -> {
return false
}