Доработки, исправления.
This commit is contained in:
parent
8fb7f4f6c5
commit
8d8c527110
@ -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")
|
||||
|
||||
|
||||
@ -41,5 +41,14 @@ class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun round(initValue: Any, digitsAfterDot: Int): Double {
|
||||
var multiplier: Int = 10
|
||||
for (i in 1..<digitsAfterDot) {
|
||||
multiplier *= 10
|
||||
}
|
||||
val value = initValue.toString().toDouble()
|
||||
return kotlin.math.round(value * multiplier) / multiplier
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,7 @@ import net.md_5.bungee.api.chat.HoverEvent
|
||||
import net.md_5.bungee.api.chat.ClickEvent
|
||||
import net.md_5.bungee.api.chat.TextComponent
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.plugin.Plugin
|
||||
import org.bukkit.scheduler.BukkitRunnable
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
@ -23,6 +24,7 @@ import java.util.Properties
|
||||
import kotlin.collections.mutableMapOf
|
||||
import kotlin.math.abs
|
||||
import java.util.Date
|
||||
import kotlin.math.round
|
||||
|
||||
class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
||||
companion object {
|
||||
@ -35,6 +37,7 @@ class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
||||
lateinit var COMMAND_REMOVE_MODE: String
|
||||
lateinit var COMMAND_REMOVE_COINS: String
|
||||
lateinit var COMMAND_REMOVE_ERROR: String
|
||||
var LOCAL_CURRENCY_MINIMUM: Double = DEFAULT_LOCAL_CURRENCY_MINIMUM
|
||||
lateinit var COURSE_MODE: String
|
||||
var COURSE_STATIC_VALUE: Double = DEFAULT_COURSE_STATIC_VALUE
|
||||
lateinit var COURSE_DYNAMIC_COMMAND: String
|
||||
@ -49,17 +52,22 @@ class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
||||
const val DEFAULT_COMMAND_REMOVE_MODE: String = "console"
|
||||
const val DEFAULT_COMMAND_REMOVE_COINS: String = "eco take %player% %amount%"
|
||||
const val DEFAULT_COMMAND_REMOVE_ERROR: String = "Error:"
|
||||
const val DEFAULT_LOCAL_CURRENCY_MINIMUM: Double = 1.00
|
||||
const val DEFAULT_COURSE_MODE: String = "dynamic"
|
||||
const val DEFAULT_COURSE_STATIC_VALUE: Double = 1000.0
|
||||
const val DEFAULT_COURSE_DYNAMIC_COMMAND: String = "baltop force"
|
||||
const val DEFAULT_COURSE_COMMISSION: Float = 5.0f
|
||||
const val DEFAULT_INVOICE_TIMEOUT_SECONDS: Long = 300 // 5 minutes
|
||||
|
||||
// Static configurations
|
||||
const val PREFIX = "&9[&bVPC&7-&6I&9] &3"
|
||||
const val NUM_AFTER_DOT = 4
|
||||
|
||||
// Utility instances
|
||||
lateinit var LOGGER: MyLogger
|
||||
lateinit var SERVER: org.bukkit.Server
|
||||
// var PLUGIN: org.bukkit.plugin.Plugin = Bukkit.getPluginManager().getPlugin("vp_server_integration")
|
||||
lateinit var PLUGIN: org.bukkit.plugin.Plugin
|
||||
|
||||
// For background checks
|
||||
@JvmStatic
|
||||
@ -105,6 +113,7 @@ class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
||||
COMMAND_REMOVE_MODE = properties.getProperty("command_remove_mode", DEFAULT_COMMAND_REMOVE_MODE).replace("'", "")
|
||||
COMMAND_REMOVE_COINS = properties.getProperty("command_remove_coins", DEFAULT_COMMAND_REMOVE_COINS).replace("'", "")
|
||||
COMMAND_REMOVE_ERROR = properties.getProperty("command_remove_error", DEFAULT_COMMAND_REMOVE_ERROR).replace("'", "")
|
||||
LOCAL_CURRENCY_MINIMUM = properties.getProperty("command_remove_error", DEFAULT_LOCAL_CURRENCY_MINIMUM.toString()).replace("'", "").toDouble()
|
||||
COURSE_MODE = properties.getProperty("course_mode", DEFAULT_COURSE_MODE).replace("'", "")
|
||||
COURSE_STATIC_VALUE = properties.getProperty("course_static_value", DEFAULT_COURSE_STATIC_VALUE.toString()).replace("'", "").toDouble()
|
||||
COURSE_DYNAMIC_COMMAND = properties.getProperty("course_dynamic_command", DEFAULT_COURSE_DYNAMIC_COMMAND).replace("'", "")
|
||||
@ -153,6 +162,9 @@ command_remove_coins='$DEFAULT_COMMAND_REMOVE_COINS'
|
||||
|
||||
# What shouldn't be in response after executing command
|
||||
command_remove_error='$DEFAULT_COMMAND_REMOVE_ERROR'
|
||||
|
||||
# What is minimum Local Currency can be?
|
||||
local_currency_minimum=1
|
||||
# -------------------- END ------------------------
|
||||
|
||||
# --------- Part with configure course ------------
|
||||
@ -183,6 +195,7 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
||||
override fun onEnable() {
|
||||
// Get server instance
|
||||
SERVER = Bukkit.getServer()
|
||||
PLUGIN = this
|
||||
|
||||
// Load configuration
|
||||
loadConfiguration()
|
||||
@ -219,18 +232,33 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
||||
(args.size == 3 || args.size == 4) && args[0] == "convert" -> {
|
||||
handleCurrencyConversion(sender, args)
|
||||
}
|
||||
|
||||
// Show usage for convert command
|
||||
args.isNotEmpty() && args[0] == "convert" -> {
|
||||
Utils.send(sender, "/vpi convert <vpc/lc> <сумма>")
|
||||
}
|
||||
|
||||
// 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<out String>) {
|
||||
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<out String>): List<String> {
|
||||
@ -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)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user