From 87f4ed5a8971dab82aab5eeea14062092b50bb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C6=B0=C6=A1ng=20H=E1=BB=93ng=20=C3=82n?= Date: Fri, 14 Jun 2024 22:14:17 +0700 Subject: [PATCH] fix import bossbar on 1.8 --- .../main/java/net/minevn/dotman/config/Milestones.kt | 11 ++++------- .../net/minevn/dotman/config/MilestonesMaster.kt | 6 ++---- .../java/net/minevn/dotman/utils/BukkitBossBar.kt | 12 ++++++++++++ .../src/main/java/net/minevn/dotman/utils/Utils.kt | 9 --------- 4 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 dotman-plugin/src/main/java/net/minevn/dotman/utils/BukkitBossBar.kt diff --git a/dotman-plugin/src/main/java/net/minevn/dotman/config/Milestones.kt b/dotman-plugin/src/main/java/net/minevn/dotman/config/Milestones.kt index 22cf9d2..d77c5c8 100644 --- a/dotman-plugin/src/main/java/net/minevn/dotman/config/Milestones.kt +++ b/dotman-plugin/src/main/java/net/minevn/dotman/config/Milestones.kt @@ -3,14 +3,12 @@ package net.minevn.dotman.config import net.minevn.dotman.DotMan import net.minevn.dotman.TOP_KEY_DONATE_TOTAL import net.minevn.dotman.database.PlayerDataDAO +import net.minevn.dotman.utils.BukkitBossBar import net.minevn.dotman.utils.Utils.Companion.format import net.minevn.dotman.utils.Utils.Companion.info import net.minevn.dotman.utils.Utils.Companion.warning import net.minevn.libs.bukkit.runSync import org.bukkit.Bukkit -import org.bukkit.boss.BarColor -import org.bukkit.boss.BarStyle -import org.bukkit.boss.BossBar import org.bukkit.entity.Player import org.bukkit.scheduler.BukkitTask @@ -61,15 +59,14 @@ class Milestones : FileConfig("mocnap") { fun getAll() = components.toList() class Component(val type: String, val amount: Int, val commands: List, val bossBar: String? = null, - val from: Int = 0, barColor : BarColor = BarColor.GREEN, - barStyle: BarStyle = BarStyle.SEGMENTED_10) { + val from: Int = 0, barColor: String = "GREEN", barStyle: String = "SEGMENTED_10") { - var bar: BossBar? = null + var bar: BukkitBossBar? = null var barTask: BukkitTask? = null; private set init { if (bossBar != null) { - bar = Bukkit.createBossBar("§r", barColor, barStyle).apply { + bar = BukkitBossBar("r", barColor, barStyle).apply { isVisible = false barTask = Bukkit.getScheduler().runTaskTimerAsynchronously(DotMan.instance, Runnable { val current = PlayerDataDAO.getInstance().getSumData("${TOP_KEY_DONATE_TOTAL}_$type") diff --git a/dotman-plugin/src/main/java/net/minevn/dotman/config/MilestonesMaster.kt b/dotman-plugin/src/main/java/net/minevn/dotman/config/MilestonesMaster.kt index 9a52523..bc04f21 100644 --- a/dotman-plugin/src/main/java/net/minevn/dotman/config/MilestonesMaster.kt +++ b/dotman-plugin/src/main/java/net/minevn/dotman/config/MilestonesMaster.kt @@ -1,8 +1,6 @@ package net.minevn.dotman.config import net.minevn.dotman.config.Milestones.Component -import net.minevn.dotman.utils.Utils.Companion.getBarColor -import net.minevn.dotman.utils.Utils.Companion.getBarStyle import net.minevn.dotman.utils.Utils.Companion.info import net.minevn.dotman.utils.Utils.Companion.warning import net.minevn.libs.bukkit.color @@ -23,8 +21,8 @@ class MilestonesMaster : FileConfig("mocnaptong") { val type = it["type"] val bossBar = (it.getOrDefault("bossbar", null) as String?)?.color() val from = it.getOrDefault("from", 0) as Int - val barColor = getBarColor(it.getOrDefault("bossbar-color", null) as String?) - val barStyle = getBarStyle(it.getOrDefault("bossbar-style", null) as String?) + val barColor = it.getOrDefault("bossbar-color", "GREEN") as String + val barStyle = it.getOrDefault("bossbar-style", "SEGMENTED_10") as String if (type !in listOf("all", "week", "month")) { warning("Loại mốc nạp \"$type\" không hợp lệ. Chỉ chấp nhận all, week, month") diff --git a/dotman-plugin/src/main/java/net/minevn/dotman/utils/BukkitBossBar.kt b/dotman-plugin/src/main/java/net/minevn/dotman/utils/BukkitBossBar.kt new file mode 100644 index 0000000..263381e --- /dev/null +++ b/dotman-plugin/src/main/java/net/minevn/dotman/utils/BukkitBossBar.kt @@ -0,0 +1,12 @@ +package net.minevn.dotman.utils + +import org.bukkit.Bukkit +import org.bukkit.boss.BarColor +import org.bukkit.boss.BarStyle +import org.bukkit.boss.BossBar + +/** + * Vì 1.8 không có BossBar nên phải tạo class này + */ +class BukkitBossBar(title: String, color: String, style: String) : BossBar +by Bukkit.createBossBar(title, BarColor.valueOf(color), BarStyle.valueOf(style)) diff --git a/dotman-plugin/src/main/java/net/minevn/dotman/utils/Utils.kt b/dotman-plugin/src/main/java/net/minevn/dotman/utils/Utils.kt index 2a12182..4875305 100644 --- a/dotman-plugin/src/main/java/net/minevn/dotman/utils/Utils.kt +++ b/dotman-plugin/src/main/java/net/minevn/dotman/utils/Utils.kt @@ -9,8 +9,6 @@ import net.minevn.dotman.DotMan import net.minevn.libs.anvilgui.AnvilGUI import net.minevn.libs.xseries.XMaterial import org.bukkit.Bukkit -import org.bukkit.boss.BarColor -import org.bukkit.boss.BarStyle import org.bukkit.command.CommandSender import org.bukkit.scheduler.BukkitTask import java.text.DecimalFormat @@ -89,13 +87,6 @@ class Utils { } } - fun getBarColor(str : String?) = BarColor.entries.firstOrNull { it.name.equals(str, true) } - ?: BarColor.GREEN - - fun getBarStyle(str : String?) = BarStyle.entries.firstOrNull { it.name.equals(str, true) } - ?: BarStyle.SOLID - - fun Int.format(): String { val format = DecimalFormat("#,###") val decimalFormatSymbols = format.decimalFormatSymbols