Skip to content

Commit 69e1ea8

Browse files
Add player list widget (SkyblockerMod#1086)
1 parent c4f9bc4 commit 69e1ea8

File tree

8 files changed

+90
-29
lines changed

8 files changed

+90
-29
lines changed

src/main/java/de/hysky/skyblocker/skyblock/chat/filters/AdFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public AdFilter() {
2020
// 1. Player name
2121
// 2. Message
2222
// (?:\[[0-9]+\] )?(?:[<INSERT EMBLEMS>] )?(?:\[[A-Z+]+\] )?([A-Za-z0-9_]+): (.+)
23-
super("(?:\\[[0-9]+\\] )?(?:[" + Constants.LEVEL_EMBLEMS+ "] )?(?:\\[[A-Z+]+\\] )?([A-Za-z0-9_]+): (.+)");
23+
super(Constants.PLAYER_NAME.pattern() + ": (.+)");
2424
}
2525

2626
@Override
@@ -36,4 +36,4 @@ public boolean onMatch(Text _message, Matcher matcher) {
3636
protected ChatFilterResult state() {
3737
return SkyblockerConfigManager.get().chat.hideAds;
3838
}
39-
}
39+
}

src/main/java/de/hysky/skyblocker/skyblock/chat/filters/ShowOffFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ShowOffFilter extends SimpleChatFilter {
99

1010
public ShowOffFilter() {
1111
//(?:\[[0-9]+\] )?(?:[<INSERT EMBLEMS>] )?(?:\[[A-Z+]+\] )?([A-Za-z0-9_]+) (?:<INSERT SHOW TYPES>) \[(.+)\]
12-
super("(?:\\[[0-9]+\\] )?(?:[" + Constants.LEVEL_EMBLEMS + "] )?(?:\\[[A-Z+]+\\] )?([A-Za-z0-9_]+) (?:" + String.join("|", SHOW_TYPES) + ") \\[(.+)\\]");
12+
super(Constants.PLAYER_NAME.pattern() + " (?:" + String.join("|", SHOW_TYPES) + ") \\[(.+)\\]");
1313
}
1414

1515
@Override

src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/preview/PreviewTab.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.hysky.skyblocker.skyblock.tabhud.config.preview;
22

3+
import com.mojang.authlib.GameProfile;
34
import de.hysky.skyblocker.config.SkyblockerConfigManager;
45
import de.hysky.skyblocker.skyblock.tabhud.config.DungeonsTabPlaceholder;
56
import de.hysky.skyblocker.skyblock.tabhud.config.WidgetsConfigurationScreen;
@@ -25,6 +26,7 @@
2526
import net.minecraft.client.gui.widget.ClickableWidget;
2627
import net.minecraft.client.gui.widget.ScrollableWidget;
2728
import net.minecraft.client.gui.widget.TextWidget;
29+
import net.minecraft.client.network.PlayerListEntry;
2830
import net.minecraft.item.ItemStack;
2931
import net.minecraft.scoreboard.ScoreHolder;
3032
import net.minecraft.scoreboard.Scoreboard;
@@ -41,6 +43,7 @@
4143
import java.util.ArrayList;
4244
import java.util.List;
4345
import java.util.Optional;
46+
import java.util.UUID;
4447
import java.util.concurrent.atomic.AtomicBoolean;
4548
import java.util.function.Consumer;
4649

@@ -236,7 +239,11 @@ private void updatePlayerListFromPreview() {
236239
}
237240
}
238241
}
239-
PlayerListMgr.updateWidgetsFrom(lines);
242+
PlayerListMgr.updateWidgetsFrom(lines.stream().map(line -> {
243+
PlayerListEntry playerListEntry = new PlayerListEntry(new GameProfile(UUID.randomUUID(), ""), false);
244+
playerListEntry.setDisplayName(line);
245+
return playerListEntry;
246+
}).toList());
240247
}
241248

242249
void updateWidgets() {

src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java

+27-18
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static void updateList() {
7979
if (Utils.isInDungeons()) {
8080
updateDungeons(null);
8181
} else {
82-
updateWidgetsFrom(playerList.stream().map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).toList());
82+
updateWidgetsFrom(playerList);
8383
}
8484
}
8585

@@ -116,17 +116,22 @@ public static void updateDungeons(List<Text> lines) {
116116
*
117117
* @param lines in-game TAB
118118
*/
119-
public static void updateWidgetsFrom(List<Text> lines) {
119+
public static void updateWidgetsFrom(List<PlayerListEntry> lines) {
120120
final Predicate<String> playersColumnPredicate = PLAYERS_COLUMN_PATTERN.asMatchPredicate();
121121
final Predicate<String> infoColumnPredicate = INFO_COLUMN_PATTERN.asMatchPredicate();
122122

123123
tabWidgetsToShow.clear();
124124
boolean doingPlayers = false;
125125
boolean playersDone = false;
126126
IntObjectPair<String> hypixelWidgetName = IntObjectPair.of(0xFFFF00, "");
127+
// These two lists should match each other.
128+
// playerListEntries is only used for the player list widget
127129
List<Text> contents = new ArrayList<>();
130+
List<PlayerListEntry> playerListEntries = new ArrayList<>();
128131

129-
for (Text displayName : lines) {
132+
for (PlayerListEntry playerListEntry : lines) {
133+
Text displayName = playerListEntry.getDisplayName();
134+
if (displayName == null) continue;
130135
String string = displayName.getString();
131136

132137
if (string.isBlank()) continue;
@@ -143,8 +148,9 @@ public static void updateWidgetsFrom(List<Text> lines) {
143148
// Check if info, if it is, dip out
144149
if (infoColumnPredicate.test(string)) {
145150
playersDone = true;
146-
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
151+
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
147152
contents.clear();
153+
playerListEntries.clear();
148154
continue;
149155
}
150156
} else {
@@ -153,18 +159,23 @@ public static void updateWidgetsFrom(List<Text> lines) {
153159
// Now check for : because of the farming contest ACTIVE
154160
// Check for mining event minutes CUZ THEY FUCKING FORGOT THE SPACE iefzeoifzeoifomezhif
155161
if (!string.startsWith(" ") && string.contains(":") && (!hypixelWidgetName.right().startsWith("Mining Event") || !string.toLowerCase().startsWith("ends in"))) {
156-
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
162+
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
157163
contents.clear();
164+
playerListEntries.clear();
158165
Pair<IntObjectPair<String>, ? extends Text> nameAndInfo = getNameAndInfo(displayName);
159166
hypixelWidgetName = nameAndInfo.left();
160-
if (!nameAndInfo.right().getString().isBlank()) contents.add(trim(nameAndInfo.right()));
167+
if (!nameAndInfo.right().getString().isBlank()) {
168+
contents.add(trim(nameAndInfo.right()));
169+
playerListEntries.add(playerListEntry);
170+
}
161171
continue;
162172
}
163173
}
164174
// Add the line to the content
165175
contents.add(trim(displayName));
176+
playerListEntries.add(playerListEntry);
166177
}
167-
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
178+
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
168179
if (!tabWidgetsToShow.contains(tabWidgetInstances.get("Active Effects")) && SkyblockerConfigManager.get().uiAndVisuals.tabHud.effectsFromFooter) {
169180
tabWidgetsToShow.add(getTabHudWidget("Active Effects", List.of()));
170181
}
@@ -203,23 +214,21 @@ private static Text trim(Text text) {
203214
return out;
204215
}
205216

206-
private static TabHudWidget getTabHudWidget(IntObjectPair<String> hypixelWidgetName, List<Text> lines) {
217+
private static TabHudWidget getTabHudWidget(IntObjectPair<String> hypixelWidgetName, List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
218+
TabHudWidget tabHudWidget;
207219
if (tabWidgetInstances.containsKey(hypixelWidgetName.right())) {
208-
TabHudWidget tabHudWidget = tabWidgetInstances.get(hypixelWidgetName.right());
209-
tabHudWidget.updateFromTab(lines);
210-
tabHudWidget.update();
211-
return tabHudWidget;
220+
tabHudWidget = tabWidgetInstances.get(hypixelWidgetName.right());
212221
} else {
213-
DefaultTabHudWidget defaultTabHudWidget = new DefaultTabHudWidget(hypixelWidgetName.right(), Text.literal(hypixelWidgetName.right()).formatted(Formatting.BOLD), hypixelWidgetName.firstInt());
214-
ScreenMaster.addWidgetInstance(defaultTabHudWidget);
215-
defaultTabHudWidget.updateFromTab(lines);
216-
defaultTabHudWidget.update();
217-
return defaultTabHudWidget;
222+
tabHudWidget = new DefaultTabHudWidget(hypixelWidgetName.right(), Text.literal(hypixelWidgetName.right()).formatted(Formatting.BOLD), hypixelWidgetName.firstInt());
223+
ScreenMaster.addWidgetInstance(tabHudWidget);
218224
}
225+
tabHudWidget.updateFromTab(lines, playerListEntries);
226+
tabHudWidget.update();
227+
return tabHudWidget;
219228
}
220229

221230
private static TabHudWidget getTabHudWidget(String hypixelWidgetName, List<Text> lines) {
222-
return getTabHudWidget(IntObjectPair.of(0xFFFF0000, hypixelWidgetName), lines);
231+
return getTabHudWidget(IntObjectPair.of(0xFFFF0000, hypixelWidgetName), lines, null);
223232
}
224233

225234
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de.hysky.skyblocker.skyblock.tabhud.widget;
2+
3+
import de.hysky.skyblocker.annotations.RegisterWidget;
4+
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
5+
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlayerComponent;
6+
import net.minecraft.client.network.PlayerListEntry;
7+
import net.minecraft.text.MutableText;
8+
import net.minecraft.text.Text;
9+
import net.minecraft.util.Formatting;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
import java.util.List;
13+
14+
@RegisterWidget
15+
public class PlayerListWidget extends TabHudWidget {
16+
private static final MutableText TITLE = Text.literal("Players").formatted(Formatting.BOLD);
17+
18+
public PlayerListWidget() {
19+
super("Players", TITLE, Formatting.AQUA.getColorValue());
20+
}
21+
22+
@Override
23+
protected void updateContent(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
24+
if (playerListEntries == null) {
25+
lines.forEach(text -> addComponent(new PlainTextComponent(text)));
26+
} else {
27+
playerListEntries.forEach(playerListEntry -> addComponent(new PlayerComponent(playerListEntry)));
28+
}
29+
}
30+
31+
@Override
32+
protected void updateContent(List<Text> lines) {}
33+
}

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/TabHudWidget.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import de.hysky.skyblocker.skyblock.tabhud.widget.component.Component;
44
import de.hysky.skyblocker.utils.Location;
5+
import net.minecraft.client.network.PlayerListEntry;
56
import net.minecraft.text.MutableText;
67
import net.minecraft.text.Text;
8+
import org.jetbrains.annotations.Nullable;
79

810
import java.util.ArrayList;
911
import java.util.List;
@@ -33,9 +35,9 @@ public void updateContent() {
3335
cachedComponents.forEach(super::addComponent);
3436
}
3537

36-
public void updateFromTab(List<Text> lines) {
38+
public void updateFromTab(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
3739
cachedComponents.clear();
38-
updateContent(lines);
40+
updateContent(lines, playerListEntries);
3941
}
4042

4143
/**
@@ -63,7 +65,18 @@ public final boolean isEnabledIn(Location location) {
6365
}
6466

6567
/**
66-
* Update the content from the hypixel widget's lines
68+
* Same as {@link #updateContent(List)} but only override if you need access to {@code playerListEntries}.
69+
*
70+
* @param playerListEntries the player list entries, which should match the lines.
71+
* Null in dungeons.
72+
* @see #updateContent(List)
73+
*/
74+
protected void updateContent(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
75+
updateContent(lines);
76+
}
77+
78+
/**
79+
* Updates the content from the hypixel widget's lines
6780
*
6881
* @param lines the lines, they are formatted and trimmed, no blank lines will be present.
6982
* If the vanilla tab widget has text right after the : they will be put on the first line.

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ public class PlayerComponent extends Component {
1919

2020
public PlayerComponent(PlayerListEntry ple) {
2121

22-
boolean plainNames = false;
23-
Team team = ple.getScoreboardTeam();
24-
String username = ple.getProfile().getName();
25-
name = (team != null && !plainNames) ? Text.empty().append(team.getPrefix()).append(Text.literal(username).formatted(team.getColor())).append(team.getSuffix()) : Text.of(username);
22+
name = ple.getDisplayName();
2623
tex = ple.getSkinTextures().texture();
2724

2825
this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);

src/main/java/de/hysky/skyblocker/utils/Constants.java

+2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import java.util.List;
99
import java.util.Map;
1010
import java.util.function.Supplier;
11+
import java.util.regex.Pattern;
1112

1213
/**
1314
* Holds generic static constants
1415
*/
1516
public interface Constants {
1617
String LEVEL_EMBLEMS = "\u2E15\u273F\u2741\u2E19\u03B1\u270E\u2615\u2616\u2663\u213B\u2694\u27B6\u26A1\u2604\u269A\u2693\u2620\u269B\u2666\u2660\u2764\u2727\u238A\u1360\u262C\u269D\u29C9\uA214\u32D6\u2E0E\u26A0\uA541\u3020\u30C4\u2948\u2622\u2623\u273E\u269C\u0BD0\u0A6D\u2742\u16C3\u3023\u10F6\u0444\u266A\u266B\u04C3\u26C1\u26C3\u16DD\uA03E\u1C6A\u03A3\u09EB\u2603\u2654\u26C2\u0FC7\uA925\uA56A\u2592\u12DE";
18+
Pattern PLAYER_NAME = Pattern.compile("(?:\\[[0-9]+\\] )?(?:[" + Constants.LEVEL_EMBLEMS + "] )?(?:\\[[A-Z+]+\\] )?([A-Za-z0-9_]+)");
1719

1820
Supplier<MutableText> PREFIX = () -> {
1921
LocalDate time = LocalDate.now();

0 commit comments

Comments
 (0)