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);