aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2023-06-19 23:31:55 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2023-06-19 23:31:55 -0400
commitbc8f4c4f75432a6e516c86990a1e6f52136b21a3 (patch)
tree0a211a46b43f00492b3e0630a9f9b82fc18b9002 /src/main/java/me/xmrvizzy/skyblocker
parentf3dd77b530bc3fb0866b16eea334fdbe3b5642de (diff)
downloadSkyblocker-bc8f4c4f75432a6e516c86990a1e6f52136b21a3.tar.gz
Skyblocker-bc8f4c4f75432a6e516c86990a1e6f52136b21a3.tar.bz2
Skyblocker-bc8f4c4f75432a6e516c86990a1e6f52136b21a3.zip
Format file
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java259
1 files 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 82a4ae01..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
@@ -18,137 +18,138 @@ 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;
- }
-
- /**
- * 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<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();
+ }
}