Доработки, исправления.
This commit is contained in:
parent
8fb7f4f6c5
commit
8d8c527110
@ -12,7 +12,6 @@ class TotalBalanceModules {
|
|||||||
LOGGER.info("Calculating dynamic rate using baltop")
|
LOGGER.info("Calculating dynamic rate using baltop")
|
||||||
// Force update balance top and delay to avoid empty string
|
// Force update balance top and delay to avoid empty string
|
||||||
CommandCapture.execute("baltop force")
|
CommandCapture.execute("baltop force")
|
||||||
Thread.sleep(300)
|
|
||||||
val output = CommandCapture.execute("baltop")
|
val output = CommandCapture.execute("baltop")
|
||||||
LOGGER.info("Balance top command output: $output")
|
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.ClickEvent
|
||||||
import net.md_5.bungee.api.chat.TextComponent
|
import net.md_5.bungee.api.chat.TextComponent
|
||||||
import org.bukkit.ChatColor
|
import org.bukkit.ChatColor
|
||||||
|
import org.bukkit.plugin.Plugin
|
||||||
import org.bukkit.scheduler.BukkitRunnable
|
import org.bukkit.scheduler.BukkitRunnable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
@ -23,6 +24,7 @@ import java.util.Properties
|
|||||||
import kotlin.collections.mutableMapOf
|
import kotlin.collections.mutableMapOf
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import kotlin.math.round
|
||||||
|
|
||||||
class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
||||||
companion object {
|
companion object {
|
||||||
@ -35,6 +37,7 @@ class Vp_server_integration() : JavaPlugin(), CommandExecutor {
|
|||||||
lateinit var COMMAND_REMOVE_MODE: String
|
lateinit var COMMAND_REMOVE_MODE: String
|
||||||
lateinit var COMMAND_REMOVE_COINS: String
|
lateinit var COMMAND_REMOVE_COINS: String
|
||||||
lateinit var COMMAND_REMOVE_ERROR: String
|
lateinit var COMMAND_REMOVE_ERROR: String
|
||||||
|
var LOCAL_CURRENCY_MINIMUM: Double = DEFAULT_LOCAL_CURRENCY_MINIMUM
|
||||||
lateinit var COURSE_MODE: String
|
lateinit var COURSE_MODE: String
|
||||||
var COURSE_STATIC_VALUE: Double = DEFAULT_COURSE_STATIC_VALUE
|
var COURSE_STATIC_VALUE: Double = DEFAULT_COURSE_STATIC_VALUE
|
||||||
lateinit var COURSE_DYNAMIC_COMMAND: String
|
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_MODE: String = "console"
|
||||||
const val DEFAULT_COMMAND_REMOVE_COINS: String = "eco take %player% %amount%"
|
const val DEFAULT_COMMAND_REMOVE_COINS: String = "eco take %player% %amount%"
|
||||||
const val DEFAULT_COMMAND_REMOVE_ERROR: String = "Error:"
|
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_MODE: String = "dynamic"
|
||||||
const val DEFAULT_COURSE_STATIC_VALUE: Double = 1000.0
|
const val DEFAULT_COURSE_STATIC_VALUE: Double = 1000.0
|
||||||
const val DEFAULT_COURSE_DYNAMIC_COMMAND: String = "baltop force"
|
const val DEFAULT_COURSE_DYNAMIC_COMMAND: String = "baltop force"
|
||||||
const val DEFAULT_COURSE_COMMISSION: Float = 5.0f
|
const val DEFAULT_COURSE_COMMISSION: Float = 5.0f
|
||||||
const val DEFAULT_INVOICE_TIMEOUT_SECONDS: Long = 300 // 5 minutes
|
const val DEFAULT_INVOICE_TIMEOUT_SECONDS: Long = 300 // 5 minutes
|
||||||
|
|
||||||
|
// Static configurations
|
||||||
const val PREFIX = "&9[&bVPC&7-&6I&9] &3"
|
const val PREFIX = "&9[&bVPC&7-&6I&9] &3"
|
||||||
|
const val NUM_AFTER_DOT = 4
|
||||||
|
|
||||||
// Utility instances
|
// Utility instances
|
||||||
lateinit var LOGGER: MyLogger
|
lateinit var LOGGER: MyLogger
|
||||||
lateinit var SERVER: org.bukkit.Server
|
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
|
// For background checks
|
||||||
@JvmStatic
|
@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_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_COINS = properties.getProperty("command_remove_coins", DEFAULT_COMMAND_REMOVE_COINS).replace("'", "")
|
||||||
COMMAND_REMOVE_ERROR = properties.getProperty("command_remove_error", DEFAULT_COMMAND_REMOVE_ERROR).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_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_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("'", "")
|
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
|
# What shouldn't be in response after executing command
|
||||||
command_remove_error='$DEFAULT_COMMAND_REMOVE_ERROR'
|
command_remove_error='$DEFAULT_COMMAND_REMOVE_ERROR'
|
||||||
|
|
||||||
|
# What is minimum Local Currency can be?
|
||||||
|
local_currency_minimum=1
|
||||||
# -------------------- END ------------------------
|
# -------------------- END ------------------------
|
||||||
|
|
||||||
# --------- Part with configure course ------------
|
# --------- Part with configure course ------------
|
||||||
@ -183,6 +195,7 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
|||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
// Get server instance
|
// Get server instance
|
||||||
SERVER = Bukkit.getServer()
|
SERVER = Bukkit.getServer()
|
||||||
|
PLUGIN = this
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
loadConfiguration()
|
loadConfiguration()
|
||||||
@ -219,18 +232,33 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
|||||||
(args.size == 3 || args.size == 4) && args[0] == "convert" -> {
|
(args.size == 3 || args.size == 4) && args[0] == "convert" -> {
|
||||||
handleCurrencyConversion(sender, args)
|
handleCurrencyConversion(sender, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show usage for convert command
|
|
||||||
args.isNotEmpty() && args[0] == "convert" -> {
|
args.isNotEmpty() && args[0] == "convert" -> {
|
||||||
Utils.send(sender, "/vpi convert <vpc/lc> <сумма>")
|
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
|
// Handle authentication command
|
||||||
args.size == 2 && args[0] == "auth" -> {
|
args.size == 2 && args[0] == "auth" -> {
|
||||||
handleAuthentication(sender, args)
|
handleAuthentication(sender, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show usage for auth command
|
|
||||||
args.isNotEmpty() && args[0] == "auth" -> {
|
args.isNotEmpty() && args[0] == "auth" -> {
|
||||||
Utils.send(sender, "/vpi auth <ник>")
|
Utils.send(sender, "/vpi auth <ник>")
|
||||||
}
|
}
|
||||||
@ -297,7 +325,7 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
|||||||
return if (COURSE_MODE == "static") {
|
return if (COURSE_MODE == "static") {
|
||||||
COURSE_STATIC_VALUE
|
COURSE_STATIC_VALUE
|
||||||
} else {
|
} 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
|
* Handle VPC to local currency conversion
|
||||||
*/
|
*/
|
||||||
private fun handleVpcConversion(sender: Player, amount: Double, course: Double, args: Array<out String>) {
|
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)
|
val vpcUsername = DataManager.getPlayerVPCUsername(sender.name)
|
||||||
if (vpcUsername == null) {
|
if (vpcUsername == null) {
|
||||||
Utils.send(sender, "&cВы должны авторизоваться сначала: /vpi auth")
|
Utils.send(sender, "&cВы должны авторизоваться сначала: /vpi auth")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (amountVPC < 0.0001 || amount < 1)
|
||||||
|
|
||||||
if (args.size == 4) {
|
if (args.size == 4) {
|
||||||
// Execute confirmed conversion
|
// Execute confirmed conversion
|
||||||
LOGGER.info("Executing confirmed conversion - Step 5")
|
LOGGER.info("Executing confirmed conversion - Step 5")
|
||||||
@ -475,13 +505,14 @@ invoice_timeout_seconds=$DEFAULT_INVOICE_TIMEOUT_SECONDS
|
|||||||
private fun showHelpMenu(sender: CommandSender) {
|
private fun showHelpMenu(sender: CommandSender) {
|
||||||
Utils.send(sender, """Использование команд:
|
Utils.send(sender, """Использование команд:
|
||||||
/vpi auth <ник> - Авторизация
|
/vpi auth <ник> - Авторизация
|
||||||
|
/vpi course - Текущий курс
|
||||||
/vpi convert <куда: vpc/lc> <сумма> - Обмен VPC на локальную валюту или наоборот
|
/vpi convert <куда: vpc/lc> <сумма> - Обмен VPC на локальную валюту или наоборот
|
||||||
|
|
||||||
Почему 'VPC-I'? Потому что это интеграция на конечном сервере - 'VPC Integration'
|
Почему 'VPC-I'? Потому что это интеграция на конечном сервере - 'VPC Integration'
|
||||||
|
|
||||||
Соглашение: voidproject.del.pw/vpc_agreement
|
Кошелёк VPC:
|
||||||
Группа ТГ: @void_project_mc
|
ТГ: https://t.me/vp_coin_bot
|
||||||
Группа ДС: discord.gg/zwNt5DJj6J""".trimIndent())
|
ДС: Кошелёк VPC#3531""".trimIndent())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array<out String>): List<String> {
|
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)) {
|
if (command.name.equals("vpi", ignoreCase = true)) {
|
||||||
when (args.size) {
|
when (args.size) {
|
||||||
1 -> {
|
1 -> {
|
||||||
completions.addAll(listOf("help", "convert", "auth"))
|
completions.addAll(listOf("help", "convert", "auth", "course"))
|
||||||
}
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
if (args[0].equals("convert", ignoreCase = true)) {
|
if (args[0].equals("convert", ignoreCase = true)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user