From d6777f8545f7a6d1f288329a2fa6385d550da876 Mon Sep 17 00:00:00 2001 From: msg-programs Date: Sun, 28 May 2023 11:53:59 +0200 Subject: Fix logic error in DungeonDownedWidget that may cause null pointer execptions. --- .../tabhud/widget/DungeonDownedWidget.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main/java/me') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDownedWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDownedWidget.java index 60f3313f..9bb250f7 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDownedWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDownedWidget.java @@ -3,7 +3,6 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.widget; import me.xmrvizzy.skyblocker.skyblock.tabhud.util.Ico; import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerListMgr; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent; - import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -18,15 +17,22 @@ public class DungeonDownedWidget extends Widget { public DungeonDownedWidget() { super(TITLE, Formatting.DARK_PURPLE.getColorValue()); - Formatting format = Formatting.RED; + String down = PlayerListMgr.strAt(21); - if (down != null && down.endsWith("NONE")) { - format = Formatting.GRAY; + if (down == null) { + this.addComponent(new IcoTextComponent()); + } else { + + Formatting format = Formatting.RED; + if (down.endsWith("NONE")) { + format = Formatting.GRAY; + } + int idx = down.indexOf(": "); + Text downed = (idx == -1) ? null + : Widget.simpleEntryText(down.substring(idx + 2), "Downed: ", format); + IcoTextComponent d = new IcoTextComponent(Ico.SKULL, downed); + this.addComponent(d); } - int idx = down.indexOf(": "); - Text downed = (down == null || idx== -1) ? null : Widget.simpleEntryText(down.substring(idx + 2), "Downed: ", format); - IcoTextComponent d = new IcoTextComponent(Ico.SKULL, downed); - this.addComponent(d); this.addSimpleIcoText(Ico.CLOCK, "Time:", Formatting.GRAY, 22); this.addSimpleIcoText(Ico.POTION, "Revive:", Formatting.GRAY, 23); -- cgit