Skip to content

Commit

Permalink
Fix NPE updating wing durability boss bar on player death.
Browse files Browse the repository at this point in the history
  • Loading branch information
totemo committed Dec 7, 2017
1 parent 00cb954 commit 07e4107
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>io.totemo</groupId>
<name>WingCommander</name>
<artifactId>${project.name}</artifactId>
<version>1.10.0</version>
<version>1.10.1</version>
<packaging>jar</packaging>
<description>Enables powered flight with elytra.</description>
<url>https://github.com/totemo/${project.name}</url>
Expand Down
17 changes: 10 additions & 7 deletions src/io/totemo/wingcommander/PlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ protected void updateBossBars() {

if (_gaugesPossible && WingCommander.CONFIG.WINGOMETER_ENABLED && _showWingometer) {
ItemStack chest = _player.getEquipment().getChestplate();
int remainingDurability = Material.ELYTRA.getMaxDurability() - chest.getDurability();
double fraction = remainingDurability / (double) Material.ELYTRA.getMaxDurability();
int percentage = (int) (100 * fraction);
_wingsBossBar.setColor(WingCommander.CONFIG.getBarColor(WingCommander.CONFIG.WINGOMETER_COLOURS, percentage));
_wingsBossBar.setTitle(String.format("Wings: %d%%", percentage));
_wingsBossBar.setProgress(Math.min(1.0, Math.max(0.0, fraction)));
_wingsBossBar.setVisible(true);
// On player death, chest item stack becomes null.
if (chest != null) {
int remainingDurability = Material.ELYTRA.getMaxDurability() - chest.getDurability();
double fraction = remainingDurability / (double) Material.ELYTRA.getMaxDurability();
int percentage = (int) (100 * fraction);
_wingsBossBar.setColor(WingCommander.CONFIG.getBarColor(WingCommander.CONFIG.WINGOMETER_COLOURS, percentage));
_wingsBossBar.setTitle(String.format("Wings: %d%%", percentage));
_wingsBossBar.setProgress(Math.min(1.0, Math.max(0.0, fraction)));
_wingsBossBar.setVisible(true);
}
} else {
_wingsBossBar.setVisible(false);
}
Expand Down

0 comments on commit 07e4107

Please sign in to comment.