diff --git a/src/main/kotlin/main/vp_server_integration/TotalBalanceModules.kt b/src/main/kotlin/main/vp_server_integration/TotalBalanceModules.kt index 202bea6..7147487 100644 --- a/src/main/kotlin/main/vp_server_integration/TotalBalanceModules.kt +++ b/src/main/kotlin/main/vp_server_integration/TotalBalanceModules.kt @@ -12,7 +12,6 @@ class TotalBalanceModules { LOGGER.info("Calculating dynamic rate using baltop") // Force update balance top and delay to avoid empty string CommandCapture.execute("baltop force") - Thread.sleep(300) val output = CommandCapture.execute("baltop") LOGGER.info("Balance top command output: $output") diff --git a/src/main/kotlin/main/vp_server_integration/Utils.kt b/src/main/kotlin/main/vp_server_integration/Utils.kt index d1db836..6e820c4 100644 --- a/src/main/kotlin/main/vp_server_integration/Utils.kt +++ b/src/main/kotlin/main/vp_server_integration/Utils.kt @@ -41,5 +41,14 @@ class Utils { } } } + + fun round(initValue: Any, digitsAfterDot: Int): Double { + var multiplier: Int = 10 + for (i in 1.. { handleCurrencyConversion(sender, args) } - - // Show usage for convert command args.isNotEmpty() && args[0] == "convert" -> { Utils.send(sender, "/vpi convert <сумма>") } + // Handle course command + args.isNotEmpty() && args[0] == "course" -> { + // Calculate exchange rate + val course = calculateExchangeRate() + LOGGER.info("Exchange rate calculated: $course") + if (course.isInfinite()) { + LOGGER.error("Zero global balance?") + Utils.send(sender, "&cПроизошла ошибка при расчёте курса. Обратитесь к администратору или повторите позже.") + + } else if (course == 0.0) { + LOGGER.error("Infinite global balance?") + Utils.send(sender, "&cПроизошла ошибка при расчёте курса. Обратитесь к администратору или повторите позже.") + } else { + val course2VPC = Utils.round(course * (1 - COURSE_COMMISSION / 100), NUM_AFTER_DOT) + val course2LC = Utils.round(course * (1 + COURSE_COMMISSION / 100), NUM_AFTER_DOT) + Utils.send(sender, "VPC->LC = &6$course2VPC&3 | LC->VPC = &6$course2LC") + } + } + // Handle authentication command args.size == 2 && args[0] == "auth" -> { handleAuthentication(sender, args) } - - // Show usage for auth command args.isNotEmpty() && args[0] == "auth" -> { Utils.send(sender, "/vpi auth <ник>") } @@ -297,7 +325,7 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS return if (COURSE_MODE == "static") { COURSE_STATIC_VALUE } else { - calculateDynamicRate() + Utils.round(calculateDynamicRate(), NUM_AFTER_DOT) } } @@ -338,13 +366,15 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS * Handle VPC to local currency conversion */ private fun handleVpcConversion(sender: Player, amount: Double, course: Double, args: Array) { - val amountVPC = amount / course * (1 - COURSE_COMMISSION / 100) + val amountVPC = Utils.round(amount / course * (1 - COURSE_COMMISSION / 100), NUM_AFTER_DOT) val vpcUsername = DataManager.getPlayerVPCUsername(sender.name) if (vpcUsername == null) { Utils.send(sender, "&cВы должны авторизоваться сначала: /vpi auth") return } + if (amountVPC < 0.0001 || amount < 1) + if (args.size == 4) { // Execute confirmed conversion LOGGER.info("Executing confirmed conversion - Step 5") @@ -475,13 +505,14 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS private fun showHelpMenu(sender: CommandSender) { Utils.send(sender, """Использование команд: /vpi auth <ник> - Авторизация + /vpi course - Текущий курс /vpi convert <куда: vpc/lc> <сумма> - Обмен VPC на локальную валюту или наоборот Почему 'VPC-I'? Потому что это интеграция на конечном сервере - 'VPC Integration' - Соглашение: voidproject.del.pw/vpc_agreement - Группа ТГ: @void_project_mc - Группа ДС: discord.gg/zwNt5DJj6J""".trimIndent()) + Кошелёк VPC: + ТГ: https://t.me/vp_coin_bot + ДС: Кошелёк VPC#3531""".trimIndent()) } override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array): List { @@ -489,7 +520,7 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS if (command.name.equals("vpi", ignoreCase = true)) { when (args.size) { 1 -> { - completions.addAll(listOf("help", "convert", "auth")) + completions.addAll(listOf("help", "convert", "auth", "course")) } 2 -> { if (args[0].equals("convert", ignoreCase = true)) {