Skip to content

Commit

Permalink
Prevent exceptions by performing bossbar progress range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tajobe committed Apr 23, 2016
1 parent eaa4930 commit 6748bd7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.simplemc.simpleannounce;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,30 @@ public void run()
.forEach(bossBar::addPlayer);

// show the boss bar
bossBar.show();
bossBar.setVisible(true);

// animate
final BukkitTask animationTask;
if (animate)
{
animationTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () ->
bossBar.setProgress(bossBar.getProgress() + ((reverse ? -1 : 1) * (1.0 / holdTime)))
, 0, 1L);
{
// calculate next progress bar step
double progress = bossBar.getProgress() + ((reverse ? -1 : 1) * (1.0 / holdTime));

// validate progress bar range
if (progress < 0)
{
progress = 0;
}
else if (progress > 1)
{
progress = 1;
}

// set progress
bossBar.setProgress(progress);
}, 0, 1L);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SimpleAnnounce
main: org.simplemc.simpleannounce.SimpleAnnounce
version: 1.9.1
version: 1.9.2
website: http://SimpleMC.org/simpleannounce/
author: Taylor Becker
permissions:
Expand Down

0 comments on commit 6748bd7

Please sign in to comment.