From 1f15c252969c6c09de7b4b11110b12eccf5e90da Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 17 Jun 2023 21:58:01 -0400 Subject: [PATCH 1/4] Improve Crimson Isle Tab HUD Fixed the reputation widget showing "Max -> Reputation" when you're at max reputation The faction quests text now retains its formatting to be more informative about whether you've not started, started or completed a quest --- .../skyblock/tabhud/util/PlayerListMgr.java | 37 +++++++++++++++++++ .../skyblock/tabhud/widget/QuestWidget.java | 14 ++++++- .../tabhud/widget/ReputationWidget.java | 3 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 60915bc124..f797e6d0a8 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -4,6 +4,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,6 +14,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; /** @@ -93,6 +95,41 @@ public static String strAt(int idx) { } return str; } + + /** + * Gets the display name at some index of the player list + * + * @return the text or null, if the display name is null + * + * @implNote currently designed specifically for crimson isles faction quests widget, might not work correctly without modification + * for other stuff. you've been warned! + */ + public static Text textAt4FactionQuests(int idx) { + + if(playerList == null) { + return null; + } + + if(playerList.size() <= idx) { + return null; + } + + Text txt = playerList.get(idx).getDisplayName(); + if(txt == null) { + return null; + } + + //Rebuild the text object to remove beginning space thats in all faction quest stuff + MutableText newTxt = Text.empty(); + + for(int i = 0; i < txt.getSiblings().size(); i++) { + Text current = txt.getSiblings().get(i); + String textToAppend = current.getString(); + newTxt.append(Text.literal((i == 0) ? StringUtils.removeStart(textToAppend, " ") : textToAppend ).setStyle(current.getStyle())); + } + + return newTxt; + } /** * Get the display name at some index of the player list as Text as seen in the diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java index 5c89964ef6..d13513e417 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java @@ -1,6 +1,7 @@ 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; @@ -13,12 +14,23 @@ public class QuestWidget extends Widget { private static final MutableText TITLE = Text.literal("Faction Quests").formatted(Formatting.AQUA, Formatting.BOLD); + + /** + * @return the entry at idx with it's formatting preserved + */ + public static Text passthroughEntryText(int idx) { + Text txt = PlayerListMgr.textAt4FactionQuests(idx); + if(txt == null) { + return null; + } + return txt; + } public QuestWidget() { super(TITLE, Formatting.AQUA.getColorValue()); for (int i = 51; i < 56; i++) { - Text q = Widget.plainEntryText(i); + Text q = passthroughEntryText(i); IcoTextComponent itc = new IcoTextComponent(Ico.BOOK, q); this.addComponent(itc); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/ReputationWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/ReputationWidget.java index c037962390..3685e0ca5e 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/ReputationWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/ReputationWidget.java @@ -54,8 +54,9 @@ public ReputationWidget() { this.addComponent(new ProgressComponent()); } else { float pcnt = Float.parseFloat(prog.group("prog")); + Text reputationText = state.group("from").equals("Max") ? Text.literal("Max Reputation") : Text.literal(state.group("from") + " -> " + state.group("to")); ProgressComponent pc = new ProgressComponent(Ico.LANTERN, - Text.of(state.group("from") + " -> " + state.group("to")), rep, pcnt, + reputationText, rep, pcnt, Formatting.AQUA.getColorValue()); this.addComponent(pc); } From 3c2ec1e9dc7dbcfff9f030619b0f088460841f21 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:15:25 -0400 Subject: [PATCH 2/4] Small code changes --- .../skyblock/tabhud/util/PlayerListMgr.java | 2 +- .../skyblock/tabhud/widget/QuestWidget.java | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index f797e6d0a8..665fc98179 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -104,7 +104,7 @@ public static String strAt(int idx) { * @implNote currently designed specifically for crimson isles faction quests widget, might not work correctly without modification * for other stuff. you've been warned! */ - public static Text textAt4FactionQuests(int idx) { + public static Text textAt(int idx) { if(playerList == null) { return null; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java index d13513e417..43b741bae1 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java @@ -14,23 +14,12 @@ public class QuestWidget extends Widget { private static final MutableText TITLE = Text.literal("Faction Quests").formatted(Formatting.AQUA, Formatting.BOLD); - - /** - * @return the entry at idx with it's formatting preserved - */ - public static Text passthroughEntryText(int idx) { - Text txt = PlayerListMgr.textAt4FactionQuests(idx); - if(txt == null) { - return null; - } - return txt; - } public QuestWidget() { super(TITLE, Formatting.AQUA.getColorValue()); for (int i = 51; i < 56; i++) { - Text q = passthroughEntryText(i); + Text q = PlayerListMgr.textAt(i); IcoTextComponent itc = new IcoTextComponent(Ico.BOOK, q); this.addComponent(itc); } From f3dd77b530bc3fb0866b16eea334fdbe3b5642de Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Mon, 19 Jun 2023 23:30:58 -0400 Subject: [PATCH 3/4] Improve documentation and trim trailing space --- .../skyblock/tabhud/util/PlayerListMgr.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 665fc98179..82a4ae01e3 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -119,16 +119,22 @@ public static Text textAt(int idx) { return null; } - //Rebuild the text object to remove beginning space thats in all faction quest stuff - MutableText newTxt = Text.empty(); + //Rebuild the text object to remove leading space thats in all faction quest stuff (also removes trailing space just in case) + MutableText newText = Text.empty(); + int size = txt.getSiblings().size(); - for(int i = 0; i < txt.getSiblings().size(); i++) { + for(int i = 0; i < size; i++) { Text current = txt.getSiblings().get(i); String textToAppend = current.getString(); - newTxt.append(Text.literal((i == 0) ? StringUtils.removeStart(textToAppend, " ") : textToAppend ).setStyle(current.getStyle())); + + //Trim leading & trailing space - this can only be done at the start and end otherwise it'll produce malformed results + if(i == 0) textToAppend = StringUtils.removeStart(textToAppend, " "); + if(i == size - 1) textToAppend = StringUtils.removeEnd(textToAppend, " "); + + newText.append(Text.literal(textToAppend).setStyle(current.getStyle())); } - return newTxt; + return newText; } /** From bc8f4c4f75432a6e516c86990a1e6f52136b21a3 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Mon, 19 Jun 2023 23:31:55 -0400 Subject: [PATCH 4/4] Format file --- .../skyblock/tabhud/util/PlayerListMgr.java | 259 +++++++++--------- 1 file changed, 130 insertions(+), 129 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 82a4ae01e3..5ace64ea18 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -18,137 +18,138 @@ import net.minecraft.text.Text; /** - * This class may be used to get data from the player list. - * It doesn't get its data every frame, instead, a scheduler is used to - * update the data this class is holding periodically. - * The list is sorted like in the vanilla game. + * This class may be used to get data from the player list. It doesn't get its + * data every frame, instead, a scheduler is used to update the data this class + * is holding periodically. The list is sorted like in the vanilla game. */ public class PlayerListMgr { - public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex"); - - private static List playerList; - - public static void updateList() { - - if (!Utils.isOnSkyblock()) { - return; - } - - ClientPlayNetworkHandler cpnwh = MinecraftClient.getInstance().getNetworkHandler(); - - // check is needed, else game crash on server leave - if (cpnwh != null) { - playerList = cpnwh.getPlayerList() - .stream() - .sorted(PlayerListHudAccessor.getOrdering()) - .toList(); - } - } - - /** - * Get the display name at some index of the player list and apply a pattern to - * it - * - * @return the matcher if p fully matches, else null - */ - public static Matcher regexAt(int idx, Pattern p) { - - String str = PlayerListMgr.strAt(idx); - - if (str == null) { - return null; - } - - Matcher m = p.matcher(str); - if (!m.matches()) { - LOGGER.error("no match: \"{}\" against \"{}\"", str, p); - return null; - } else { - return m; - } - } - - /** - * Get the display name at some index of the player list as string - * - * @return the string or null, if the display name is null, empty or whitespace - * only - */ - public static String strAt(int idx) { - - if (playerList == null) { - return null; - } - - if (playerList.size() <= idx) { - return null; - } - - Text txt = playerList.get(idx).getDisplayName(); - if (txt == null) { - return null; - } - String str = txt.getString().trim(); - if (str.length() == 0) { - return null; - } - return str; - } - - /** - * Gets the display name at some index of the player list - * - * @return the text or null, if the display name is null - * - * @implNote currently designed specifically for crimson isles faction quests widget, might not work correctly without modification - * for other stuff. you've been warned! - */ - public static Text textAt(int idx) { - - if(playerList == null) { - return null; - } - - if(playerList.size() <= idx) { - return null; - } - - Text txt = playerList.get(idx).getDisplayName(); - if(txt == null) { - return null; - } - - //Rebuild the text object to remove leading space thats in all faction quest stuff (also removes trailing space just in case) - MutableText newText = Text.empty(); - int size = txt.getSiblings().size(); - - for(int i = 0; i < size; i++) { - Text current = txt.getSiblings().get(i); - String textToAppend = current.getString(); - - //Trim leading & trailing space - this can only be done at the start and end otherwise it'll produce malformed results - if(i == 0) textToAppend = StringUtils.removeStart(textToAppend, " "); - if(i == size - 1) textToAppend = StringUtils.removeEnd(textToAppend, " "); - - newText.append(Text.literal(textToAppend).setStyle(current.getStyle())); - } - - return newText; - } - - /** - * Get the display name at some index of the player list as Text as seen in the - * game - * - * @return the PlayerListEntry at that index - */ - public static PlayerListEntry getRaw(int idx) { - return playerList.get(idx); - } - - public static int getSize() { - return playerList.size(); - } + public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex"); + + private static List playerList; + + public static void updateList() { + + if (!Utils.isOnSkyblock()) { + return; + } + + ClientPlayNetworkHandler cpnwh = MinecraftClient.getInstance().getNetworkHandler(); + + // check is needed, else game crash on server leave + if (cpnwh != null) { + playerList = cpnwh.getPlayerList().stream().sorted(PlayerListHudAccessor.getOrdering()).toList(); + } + } + + /** + * Get the display name at some index of the player list and apply a pattern to + * it + * + * @return the matcher if p fully matches, else null + */ + public static Matcher regexAt(int idx, Pattern p) { + + String str = PlayerListMgr.strAt(idx); + + if (str == null) { + return null; + } + + Matcher m = p.matcher(str); + if (!m.matches()) { + LOGGER.error("no match: \"{}\" against \"{}\"", str, p); + return null; + } else { + return m; + } + } + + /** + * Get the display name at some index of the player list as string + * + * @return the string or null, if the display name is null, empty or whitespace + * only + */ + public static String strAt(int idx) { + + if (playerList == null) { + return null; + } + + if (playerList.size() <= idx) { + return null; + } + + Text txt = playerList.get(idx).getDisplayName(); + if (txt == null) { + return null; + } + String str = txt.getString().trim(); + if (str.length() == 0) { + return null; + } + return str; + } + + /** + * Gets the display name at some index of the player list + * + * @return the text or null, if the display name is null + * + * @implNote currently designed specifically for crimson isles faction quests + * widget, might not work correctly without modification for other + * stuff. you've been warned! + */ + public static Text textAt(int idx) { + + if (playerList == null) { + return null; + } + + if (playerList.size() <= idx) { + return null; + } + + Text txt = playerList.get(idx).getDisplayName(); + if (txt == null) { + return null; + } + + // Rebuild the text object to remove leading space thats in all faction quest + // stuff (also removes trailing space just in case) + MutableText newText = Text.empty(); + int size = txt.getSiblings().size(); + + for (int i = 0; i < size; i++) { + Text current = txt.getSiblings().get(i); + String textToAppend = current.getString(); + + // Trim leading & trailing space - this can only be done at the start and end + // otherwise it'll produce malformed results + if (i == 0) + textToAppend = StringUtils.removeStart(textToAppend, " "); + if (i == size - 1) + textToAppend = StringUtils.removeEnd(textToAppend, " "); + + newText.append(Text.literal(textToAppend).setStyle(current.getStyle())); + } + + return newText; + } + + /** + * Get the display name at some index of the player list as Text as seen in the + * game + * + * @return the PlayerListEntry at that index + */ + public static PlayerListEntry getRaw(int idx) { + return playerList.get(idx); + } + + public static int getSize() { + return playerList.size(); + } }