🐛 Bug fixes
This commit is contained in:
@@ -5,6 +5,7 @@ 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.Bukkit.getLogger
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.command.Command
|
||||
@@ -13,7 +14,12 @@ 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?, private val messages: Map<String, String>, private val playerSolarpassMap: MutableMap<String, String?>) :
|
||||
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) {
|
||||
@@ -45,6 +51,7 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
val order: SnOrder
|
||||
try {
|
||||
order = orderSrv.getOrder(orderNumber);
|
||||
// The update validated the order is created by us
|
||||
orderSrv.updateOrderStatus(orderNumber, false);
|
||||
} catch (_: Exception) {
|
||||
p0.sendMessage(
|
||||
@@ -62,7 +69,7 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
return true;
|
||||
}
|
||||
|
||||
val bal = order.amount.toDouble() * 100;
|
||||
val bal = order.amount;
|
||||
eco?.depositPlayer(p0.player, bal)
|
||||
|
||||
val doneComponent =
|
||||
@@ -97,12 +104,13 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
|
||||
val order: SnOrder
|
||||
try {
|
||||
order = orderSrv.createOrder("Deposit to Highland MC", amount / 100);
|
||||
} catch (_: Exception) {
|
||||
order = orderSrv.createOrder("Deposit to GoatCraft", amount);
|
||||
} catch (e: Exception) {
|
||||
p0.sendMessage(
|
||||
ChatColor.RED.toString() + (messages["command_deposit_create_error"]
|
||||
?: "An error occurred while creating order. Try again later.")
|
||||
)
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,7 +124,7 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
val orderHintComponent =
|
||||
TextComponent(
|
||||
ChatColor.GRAY.toString() + (messages["command_deposit_order_created"]
|
||||
?: "Order created, number ") + ChatColor.WHITE + ChatColor.BOLD + "#${order.id}"
|
||||
?: "Order created, number ") + ChatColor.WHITE + ChatColor.BOLD + "#${order.id.take(6)}" + " "
|
||||
)
|
||||
val followingComponent = TextComponent(
|
||||
ChatColor.GRAY.toString() + (messages["command_deposit_to_payment_page"] ?: " to the payment page.")
|
||||
@@ -166,8 +174,9 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
?: "Making transaction, please stand by...")
|
||||
);
|
||||
|
||||
val bal = amount / 100;
|
||||
val resp = eco?.withdrawPlayer(p0.player, "Withdraw to Source Point - $bal SRC", amount);
|
||||
// Takes extra 20% as fee
|
||||
val fee = amount * 0.2;
|
||||
val resp = eco?.withdrawPlayer(p0.player, amount + fee);
|
||||
if (resp?.type != EconomyResponse.ResponseType.SUCCESS) {
|
||||
p0.sendMessage(
|
||||
ChatColor.RED.toString() + (messages["command_withdraw_no_money"]
|
||||
@@ -178,29 +187,28 @@ class SnCommand(private val sn: SnService, private val eco: Economy?, private va
|
||||
|
||||
try {
|
||||
val transactionSrv = SnBalanceService(sn);
|
||||
val transaction = transactionSrv.addBalance(bal, "Withdraw from GoatCraft", accountId);
|
||||
val transaction = transactionSrv.addBalance(amount, "Withdraw from GoatCraft", accountId);
|
||||
val transactionHintComponent =
|
||||
TextComponent(
|
||||
ChatColor.GREEN.toString() + (messages["command_withdraw_done"]
|
||||
?: "Done! transaction number ") + ChatColor.WHITE + ChatColor.BOLD + "#${transaction.id}"
|
||||
?: "Done! transaction number ") + ChatColor.WHITE + ChatColor.BOLD + "#${
|
||||
transaction.id.take(
|
||||
6
|
||||
)
|
||||
}"
|
||||
)
|
||||
|
||||
p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
|
||||
p0.spigot().sendMessage(transactionHintComponent)
|
||||
} catch (_: Exception) {
|
||||
eco?.depositPlayer(
|
||||
p0.player,
|
||||
(messages["command_withdraw_refund_reason"] ?: "Withdraw to Source Point Failed - Refund"),
|
||||
amount
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
eco.depositPlayer(p0.player, amount + fee)
|
||||
p0.sendMessage(
|
||||
ChatColor.RED.toString() + (messages["command_withdraw_error"]
|
||||
?: "An error occurred while making transaction. Make sure your wallet exists then try again later.")
|
||||
)
|
||||
e.printStackTrace()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
Reference in New Issue
Block a user