Skip to content

Commit

Permalink
Add edge case for boss bar to fix Archy-X#319
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Sep 26, 2024
1 parent cb43666 commit 770e276
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 770e276

Please sign in to comment.