aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2023-06-20 12:28:25 +0800
committerGitHub <noreply@github.com>2023-06-20 12:28:25 +0800
commita45c32999abf4ae9218df5e4cb75f50284256322 (patch)
tree0a211a46b43f00492b3e0630a9f9b82fc18b9002 /src/main
parentcafe56cd21b5ebc3cd17b52ee86a81ec469795a5 (diff)
parentbc8f4c4f75432a6e516c86990a1e6f52136b21a3 (diff)
downloadSkyblocker-a45c32999abf4ae9218df5e4cb75f50284256322.tar.gz
Skyblocker-a45c32999abf4ae9218df5e4cb75f50284256322.tar.bz2
Skyblocker-a45c32999abf4ae9218df5e4cb75f50284256322.zip
Merge pull request #183 from AzureAaron/crimson-isle-tabhud-improvements
Crimson Isle Tab Hud Improvements
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java220
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/QuestWidget.java3
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/ReputationWidget.java3
3 files changed, 136 insertions, 90 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 60915bc1..5ace64ea 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.List;
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,99 +14,142 @@ import me.xmrvizzy.skyblocker.utils.Utils;
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;
/**
- * 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<PlayerListEntry> 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;
- }
-
- /**
- * 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<PlayerListEntry> 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();
+ }
}
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 5c89964e..43b741ba 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;
@@ -18,7 +19,7 @@ public class QuestWidget extends Widget {
super(TITLE, Formatting.AQUA.getColorValue());
for (int i = 51; i < 56; i++) {
- Text q = Widget.plainEntryText(i);
+ Text q = PlayerListMgr.textAt(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 c0379623..3685e0ca 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 class ReputationWidget extends Widget {
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);
}