From 770e276f51b526d6da1c70f40a3b80812cd6be3a Mon Sep 17 00:00:00 2001 From: Intybyte Date: Thu, 26 Sep 2024 18:07:14 +0200 Subject: [PATCH] Add edge case for boss bar to fix #319 --- .../auraskills/bukkit/ui/BossBarManager.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/ui/BossBarManager.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/ui/BossBarManager.java index d85f23318..9911687a1 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/ui/BossBarManager.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/ui/BossBarManager.java @@ -200,11 +200,14 @@ private BossBar handleNewBossBar(Player player, Skill skill, float progressOld, Component name = tf.toComponent(text); - BossBar bossBar = BossBar.bossBar(name, progressOld, color, overlay); + float sanitizedOld = handleInvalidFloat(progressOld); + float sanitizedNew = handleInvalidFloat(progressNew); + + BossBar bossBar = BossBar.bossBar(name, sanitizedOld, color, overlay); if (!ANIMATE_PROGRESS) { // If the config option is disabled, immediately show new progress - bossBar.progress(progressNew); + bossBar.progress(sanitizedNew); } else { // Update the progress later to display its animation from progressOld to progressNew - plugin.getScheduler().scheduleSync(() -> bossBar.progress(progressNew), 2 * 50, TimeUnit.MILLISECONDS); + plugin.getScheduler().scheduleSync(() -> bossBar.progress(sanitizedNew), 2 * 50, TimeUnit.MILLISECONDS); } plugin.getAudiences().player(player).showBossBar(bossBar); @@ -217,6 +220,22 @@ private BossBar handleNewBossBar(Player player, Skill skill, float progressOld, return bossBar; } + private float handleInvalidFloat(float f) { + if (Float.isNaN(f)) { + return 0f; + } + + if (Float.isInfinite(f)) { + if (f > 0) { + return 1f; + } else { + return 0f; + } + } + + return f; + } + private void handleExistingBossBar(BossBar bossBar, Player player, Skill skill, float progress, String text) { Component name = tf.toComponent(text);