Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edge case for boss bar to fix #319 #320

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading