From 44cfb93019b4efecb88a395cbf251d39e9712367 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 3 Jan 2022 19:39:07 +0000 Subject: [PATCH] Fixed boss bar bugs --- .../willfp/ecoskills/skills/SkillDisplayListener.kt | 10 ++++++++-- eco-core/core-plugin/src/main/resources/config.yml | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt index 4c397ef..9f500d5 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt @@ -63,16 +63,22 @@ class SkillDisplayListener( string = string.replace("%gained_xp%", NumberUtils.format(amount)) val ratio = currentXp / nextLevel - val bossBar = Bukkit.createBossBar( + val key = plugin.namespacedKeyFactory.create("${player.name.substring(0, 2)}${skill.id}") + + val bossBar = Bukkit.getBossBar(key) ?: Bukkit.createBossBar( + key, string, BarColor.valueOf(this.plugin.configYml.getString("skills.progress.boss-bar.color").uppercase()), BarStyle.valueOf(this.plugin.configYml.getString("skills.progress.boss-bar.style").uppercase()) ) + bossBar.setTitle(string) bossBar.progress = ratio bossBar.addPlayer(player) - this.plugin.scheduler.runLater(this.plugin.configYml.getInt("skills.progress.boss-bar.duration").toLong()) { + this.plugin.scheduler.runLater( + this.plugin.configYml.getInt("skills.progress.boss-bar.duration").toLong() + ) { bossBar.removePlayer(player) } } diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 8748186..6be9083 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -243,11 +243,13 @@ skills: # If the boss bar should be used enabled: false # The boss bar message that should be sent - format: "&f%skill% &8| &9(%current_xp%/%required_xp%) &e+%gained_xp%" + format: "&f%skill% &8| &9(%current_xp%/%required_xp%)" # The color of the boss bar (from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/BarColor.html) color: pink # The style of the boss bar (from https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/BarStyle.html) style: solid + # How long the boss bar should last (in ticks) + duration: 60 sound: # If a sound should be played enabled: true