✨ Deposit money
This commit is contained in:
@@ -4,14 +4,16 @@ import dev.solsynth.snConnect.services.SnOrderService
|
||||
import dev.solsynth.snConnect.services.SnService
|
||||
import net.md_5.bungee.api.chat.ClickEvent
|
||||
import net.md_5.bungee.api.chat.TextComponent
|
||||
import net.milkbowl.vault.economy.Economy
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.command.TabCompleter
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class SnCommand(private val sn: SnService) : CommandExecutor {
|
||||
class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandExecutor {
|
||||
override fun onCommand(p0: CommandSender, p1: Command, p2: String, p3: Array<out String>): Boolean {
|
||||
if (p0 !is Player) {
|
||||
return false;
|
||||
@@ -26,22 +28,62 @@ class SnCommand(private val sn: SnService) : CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
val orderSrv = SnOrderService(sn);
|
||||
|
||||
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 order, please stand by...");
|
||||
val order = orderSrv.getOrder(orderNumber);
|
||||
val bal = order.amount.toDouble() * 100;
|
||||
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.")
|
||||
|
||||
p0.playSound(p0.player!!, Sound.BLOCK_ANVIL_PLACE, 1.0F, 1.0F)
|
||||
p0.spigot().sendMessage(doneComponent, moneyComponent, suffixComponent)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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.")
|
||||
return true;
|
||||
}
|
||||
|
||||
val orderSrv = SnOrderService(sn);
|
||||
p0.sendMessage(ChatColor.GRAY.toString() + "Creating order, please stand by...");
|
||||
|
||||
val order = orderSrv.createOrder("Deposit to Highland MC", amount / 100);
|
||||
|
||||
val linkComponent = TextComponent(ChatColor.GOLD.toString() + "Click here to payment page")
|
||||
val linkComponent =
|
||||
TextComponent(ChatColor.GOLD.toString() + ChatColor.UNDERLINE.toString() + ChatColor.BOLD.toString() + "click here")
|
||||
linkComponent.clickEvent =
|
||||
ClickEvent(ClickEvent.Action.OPEN_URL, "https://solsynth.dev/orders/${order.id}");
|
||||
p0.spigot().sendMessage(linkComponent);
|
||||
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.")
|
||||
p0.spigot()
|
||||
.sendMessage(orderHintComponent, linkComponent, followingComponent);
|
||||
|
||||
val afterPaidComponent =
|
||||
TextComponent(ChatColor.UNDERLINE.toString() + ChatColor.YELLOW + "After you paid, click here to confirm payment.")
|
||||
afterPaidComponent.clickEvent =
|
||||
ClickEvent(ClickEvent.Action.RUN_COMMAND, "/sn deposit confirm ${order.id}")
|
||||
p0.spigot().sendMessage(afterPaidComponent);
|
||||
}
|
||||
|
||||
else -> return false;
|
||||
else -> {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user