Balance exchange source points, link account with Solarpass with drasl

This commit is contained in:
2025-10-05 23:46:06 +08:00
parent 3803e27a06
commit a902ecef8d
14 changed files with 576 additions and 118 deletions

View File

@@ -13,7 +13,8 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player
class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandExecutor {
class SnCommand(private val sn: SnService, private val eco: Economy?, private val messages: Map<String, String>, private val playerSolarpassMap: MutableMap<String, String?>) :
CommandExecutor {
override fun onCommand(p0: CommandSender, p1: Command, p2: String, p3: Array<out String>): Boolean {
if (p0 !is Player) {
return false;
@@ -24,7 +25,10 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
when (p3[0].lowercase()) {
"deposit" -> {
if (p3.size < 2) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific an amount to deposit.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_no_amount"]
?: "You need to specify an amount to deposit.")
)
return true;
}
@@ -32,35 +36,43 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
if (p3[1].equals("confirm", ignoreCase = true) && p3.size >= 3) {
// Confirming order
val orderNumber = p3[2].toLongOrNull();
if (orderNumber == null) {
p0.sendMessage(ChatColor.RED.toString() + "Invalid order number, it must be a number.");
return true;
}
p0.sendMessage(ChatColor.GRAY.toString() + "Confirming payment, please stand by...");
val orderNumber = p3[2];
p0.sendMessage(
ChatColor.GRAY.toString() + (messages["command_deposit_confirming"]
?: "Confirming payment, please stand by...")
);
val order: SnOrder
try {
order = orderSrv.getOrder(orderNumber);
orderSrv.cancelOrder(orderNumber);
orderSrv.updateOrderStatus(orderNumber, false);
} catch (_: Exception) {
p0.sendMessage(ChatColor.RED.toString() + "An error occurred while pulling transaction. Make sure the order is exists then try again later.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_pull_error"]
?: "An error occurred while pulling transaction. Make sure the order exists then try again later.")
)
return true;
}
if (order.status != 1L) {
p0.sendMessage(ChatColor.RED.toString() + "Order was not paid yet.");
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_order_not_paid"]
?: "Order was not paid yet.")
)
return true;
}
val bal = order.amount.toDouble() * 100;
eco?.depositPlayer(p0.player, bal)
val doneComponent = TextComponent(ChatColor.GREEN.toString() + "Done!")
val doneComponent =
TextComponent(ChatColor.GREEN.toString() + (messages["command_deposit_done"] ?: "Done!"))
val moneyComponent = TextComponent(ChatColor.GOLD.toString() + ChatColor.BOLD + " $bal$")
val suffixComponent =
TextComponent(ChatColor.GREEN.toString() + " has been added to your balance.")
TextComponent(
ChatColor.GREEN.toString() + (messages["command_deposit_added_balance"]
?: " has been added to your balance.")
)
p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
p0.spigot().sendMessage(doneComponent, moneyComponent, suffixComponent)
@@ -71,32 +83,52 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
// Creating new order
val amount = p3[1].toDoubleOrNull();
if (amount == null) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific an amount of number to deposit.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_invalid_amount"]
?: "You need to specify an amount as a number to deposit.")
)
return true;
}
p0.sendMessage(ChatColor.GRAY.toString() + "Creating order, please stand by...");
p0.sendMessage(
ChatColor.GRAY.toString() + (messages["command_deposit_creating"]
?: "Creating order, please stand by...")
);
val order: SnOrder
try {
order = orderSrv.createOrder("Deposit to Highland MC", amount / 100);
} catch (_: Exception) {
p0.sendMessage(ChatColor.RED.toString() + "An error occurred while creating order. Try again later.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_create_error"]
?: "An error occurred while creating order. Try again later.")
)
return true;
}
val linkComponent =
TextComponent(ChatColor.GOLD.toString() + ChatColor.UNDERLINE.toString() + ChatColor.BOLD.toString() + "click here")
TextComponent(
ChatColor.GOLD.toString() + ChatColor.UNDERLINE.toString() + ChatColor.BOLD.toString() + (messages["command_deposit_click_here"]
?: "click here")
)
linkComponent.clickEvent =
ClickEvent(ClickEvent.Action.OPEN_URL, "https://solsynth.dev/orders/${order.id}");
ClickEvent(ClickEvent.Action.OPEN_URL, "https://solian.app/orders/${order.id}");
val orderHintComponent =
TextComponent(ChatColor.GRAY.toString() + "Order created, number " + ChatColor.WHITE + ChatColor.BOLD + "#${order.id}")
val followingComponent = TextComponent(ChatColor.GRAY.toString() + " to the payment page.")
TextComponent(
ChatColor.GRAY.toString() + (messages["command_deposit_order_created"]
?: "Order created, number ") + ChatColor.WHITE + ChatColor.BOLD + "#${order.id}"
)
val followingComponent = TextComponent(
ChatColor.GRAY.toString() + (messages["command_deposit_to_payment_page"] ?: " to the payment page.")
)
p0.spigot()
.sendMessage(orderHintComponent, linkComponent, followingComponent);
val afterPaidComponent =
TextComponent(ChatColor.UNDERLINE.toString() + ChatColor.YELLOW + "After you paid, click here to confirm payment.")
TextComponent(
ChatColor.UNDERLINE.toString() + ChatColor.YELLOW + (messages["command_deposit_after_paid"]
?: "After you paid, click here to confirm payment.")
)
afterPaidComponent.clickEvent =
ClickEvent(ClickEvent.Action.RUN_COMMAND, "/sn deposit confirm ${order.id}")
p0.spigot().sendMessage(afterPaidComponent);
@@ -104,47 +136,67 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
"withdraw" -> {
if (p3.size < 2) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific an amount to deposit.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_no_amount"]
?: "You need to specify 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.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_deposit_invalid_amount"]
?: "You need to specify an amount as a number to deposit.")
)
return true;
}
if (p3.size < 3) {
p0.sendMessage(ChatColor.RED.toString() + "You need to specific a wallet account to deposit.")
val playerUuid = p0.uniqueId.toString()
val accountId = playerSolarpassMap[playerUuid]
if (accountId == null) {
p0.sendMessage(
ChatColor.RED.toString() + "Bind your Solarpass first!"
)
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...");
p0.sendMessage(
ChatColor.GRAY.toString() + (messages["command_withdraw_making"]
?: "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.")
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_withdraw_no_money"]
?: "Your in-game account does not have enough money for that.")
)
return true;
}
try {
val transactionSrv = SnTransactionService(sn);
val transaction = transactionSrv.makeTransaction(bal, "Withdraw from Highland MC", walletId);
val transactionSrv = SnBalanceService(sn);
val transaction = transactionSrv.addBalance(bal, "Withdraw from GoatCraft", accountId);
val transactionHintComponent =
TextComponent(ChatColor.GREEN.toString() + "Done! transaction number " + ChatColor.WHITE + ChatColor.BOLD + "#${transaction.id}")
TextComponent(
ChatColor.GREEN.toString() + (messages["command_withdraw_done"]
?: "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)
} catch (_: Exception) {
eco?.depositPlayer(p0.player, "Withdraw to Source Point Failed - Refund", amount)
p0.sendMessage(ChatColor.RED.toString() + "An error occurred while making transaction. Make sure your wallet is exists then try again later.")
eco?.depositPlayer(
p0.player,
(messages["command_withdraw_refund_reason"] ?: "Withdraw to Source Point Failed - Refund"),
amount
)
p0.sendMessage(
ChatColor.RED.toString() + (messages["command_withdraw_error"]
?: "An error occurred while making transaction. Make sure your wallet exists then try again later.")
)
return true
}
@@ -172,4 +224,4 @@ class SnCommandCompleter : TabCompleter {
else -> mutableListOf();
}
}
}
}