Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add player list widget #1086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AdFilter() {
// 1. Player name
// 2. Message
// (?:\[[0-9]+\] )?(?:[<INSERT EMBLEMS>] )?(?:\[[A-Z+]+\] )?([A-Za-z0-9_]+): (.+)
super("(?:\\[[0-9]+\\] )?(?:[" + Constants.LEVEL_EMBLEMS+ "] )?(?:\\[[A-Z+]+\\] )?([A-Za-z0-9_]+): (.+)");
super(Constants.PLAYER_NAME.pattern() + ": (.+)");
}

@Override
Expand All @@ -36,4 +36,4 @@ public boolean onMatch(Text _message, Matcher matcher) {
protected ChatFilterResult state() {
return SkyblockerConfigManager.get().chat.hideAds;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ShowOffFilter extends SimpleChatFilter {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.tabhud.config.preview;

import com.mojang.authlib.GameProfile;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.config.DungeonsTabPlaceholder;
import de.hysky.skyblocker.skyblock.tabhud.config.WidgetsConfigurationScreen;
Expand All @@ -25,6 +26,7 @@
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.ScrollableWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.item.ItemStack;
import net.minecraft.scoreboard.ScoreHolder;
import net.minecraft.scoreboard.Scoreboard;
Expand All @@ -41,6 +43,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

Expand Down Expand Up @@ -236,7 +239,11 @@ private void updatePlayerListFromPreview() {
}
}
}
PlayerListMgr.updateWidgetsFrom(lines);
PlayerListMgr.updateWidgetsFrom(lines.stream().map(line -> {
PlayerListEntry playerListEntry = new PlayerListEntry(new GameProfile(UUID.randomUUID(), ""), false);
playerListEntry.setDisplayName(line);
return playerListEntry;
}).toList());
}

void updateWidgets() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void updateList() {
if (Utils.isInDungeons()) {
updateDungeons(null);
} else {
updateWidgetsFrom(playerList.stream().map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).toList());
updateWidgetsFrom(playerList);
}
}

Expand Down Expand Up @@ -116,17 +116,22 @@ public static void updateDungeons(List<Text> lines) {
*
* @param lines in-game TAB
*/
public static void updateWidgetsFrom(List<Text> lines) {
public static void updateWidgetsFrom(List<PlayerListEntry> lines) {
final Predicate<String> playersColumnPredicate = PLAYERS_COLUMN_PATTERN.asMatchPredicate();
final Predicate<String> infoColumnPredicate = INFO_COLUMN_PATTERN.asMatchPredicate();

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

for (Text displayName : lines) {
for (PlayerListEntry playerListEntry : lines) {
Text displayName = playerListEntry.getDisplayName();
if (displayName == null) continue;
String string = displayName.getString();

if (string.isBlank()) continue;
Expand All @@ -143,8 +148,9 @@ public static void updateWidgetsFrom(List<Text> lines) {
// Check if info, if it is, dip out
if (infoColumnPredicate.test(string)) {
playersDone = true;
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
contents.clear();
playerListEntries.clear();
continue;
}
} else {
Expand All @@ -153,18 +159,23 @@ public static void updateWidgetsFrom(List<Text> lines) {
// Now check for : because of the farming contest ACTIVE
// Check for mining event minutes CUZ THEY FUCKING FORGOT THE SPACE iefzeoifzeoifomezhif
if (!string.startsWith(" ") && string.contains(":") && (!hypixelWidgetName.right().startsWith("Mining Event") || !string.toLowerCase().startsWith("ends in"))) {
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
contents.clear();
playerListEntries.clear();
Pair<IntObjectPair<String>, ? extends Text> nameAndInfo = getNameAndInfo(displayName);
hypixelWidgetName = nameAndInfo.left();
if (!nameAndInfo.right().getString().isBlank()) contents.add(trim(nameAndInfo.right()));
if (!nameAndInfo.right().getString().isBlank()) {
contents.add(trim(nameAndInfo.right()));
playerListEntries.add(playerListEntry);
}
continue;
}
}
// Add the line to the content
contents.add(trim(displayName));
playerListEntries.add(playerListEntry);
}
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents));
if (!contents.isEmpty()) tabWidgetsToShow.add(getTabHudWidget(hypixelWidgetName, contents, playerListEntries));
if (!tabWidgetsToShow.contains(tabWidgetInstances.get("Active Effects")) && SkyblockerConfigManager.get().uiAndVisuals.tabHud.effectsFromFooter) {
tabWidgetsToShow.add(getTabHudWidget("Active Effects", List.of()));
}
Expand Down Expand Up @@ -203,23 +214,21 @@ private static Text trim(Text text) {
return out;
}

private static TabHudWidget getTabHudWidget(IntObjectPair<String> hypixelWidgetName, List<Text> lines) {
private static TabHudWidget getTabHudWidget(IntObjectPair<String> hypixelWidgetName, List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
TabHudWidget tabHudWidget;
if (tabWidgetInstances.containsKey(hypixelWidgetName.right())) {
TabHudWidget tabHudWidget = tabWidgetInstances.get(hypixelWidgetName.right());
tabHudWidget.updateFromTab(lines);
tabHudWidget.update();
return tabHudWidget;
tabHudWidget = tabWidgetInstances.get(hypixelWidgetName.right());
} else {
DefaultTabHudWidget defaultTabHudWidget = new DefaultTabHudWidget(hypixelWidgetName.right(), Text.literal(hypixelWidgetName.right()).formatted(Formatting.BOLD), hypixelWidgetName.firstInt());
ScreenMaster.addWidgetInstance(defaultTabHudWidget);
defaultTabHudWidget.updateFromTab(lines);
defaultTabHudWidget.update();
return defaultTabHudWidget;
tabHudWidget = new DefaultTabHudWidget(hypixelWidgetName.right(), Text.literal(hypixelWidgetName.right()).formatted(Formatting.BOLD), hypixelWidgetName.firstInt());
ScreenMaster.addWidgetInstance(tabHudWidget);
}
tabHudWidget.updateFromTab(lines, playerListEntries);
tabHudWidget.update();
return tabHudWidget;
}

private static TabHudWidget getTabHudWidget(String hypixelWidgetName, List<Text> lines) {
return getTabHudWidget(IntObjectPair.of(0xFFFF0000, hypixelWidgetName), lines);
return getTabHudWidget(IntObjectPair.of(0xFFFF0000, hypixelWidgetName), lines, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.hysky.skyblocker.skyblock.tabhud.widget;

import de.hysky.skyblocker.annotations.RegisterWidget;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlayerComponent;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Nullable;

import java.util.List;

@RegisterWidget
public class PlayerListWidget extends TabHudWidget {
private static final MutableText TITLE = Text.literal("Players").formatted(Formatting.BOLD);

public PlayerListWidget() {
super("Players", TITLE, Formatting.AQUA.getColorValue());
}

@Override
protected void updateContent(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
if (playerListEntries == null) {
lines.forEach(text -> addComponent(new PlainTextComponent(text)));
} else {
playerListEntries.forEach(playerListEntry -> addComponent(new PlayerComponent(playerListEntry)));
}
}

@Override
protected void updateContent(List<Text> lines) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import de.hysky.skyblocker.skyblock.tabhud.widget.component.Component;
import de.hysky.skyblocker.utils.Location;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -33,9 +35,9 @@ public void updateContent() {
cachedComponents.forEach(super::addComponent);
}

public void updateFromTab(List<Text> lines) {
public void updateFromTab(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
cachedComponents.clear();
updateContent(lines);
updateContent(lines, playerListEntries);
}

/**
Expand Down Expand Up @@ -63,7 +65,18 @@ public final boolean isEnabledIn(Location location) {
}

/**
* Update the content from the hypixel widget's lines
* Same as {@link #updateContent(List)} but only override if you need access to {@code playerListEntries}.
*
* @param playerListEntries the player list entries, which should match the lines.
* Null in dungeons.
* @see #updateContent(List)
*/
protected void updateContent(List<Text> lines, @Nullable List<PlayerListEntry> playerListEntries) {
updateContent(lines);
}

/**
* Updates the content from the hypixel widget's lines
*
* @param lines the lines, they are formatted and trimmed, no blank lines will be present.
* If the vanilla tab widget has text right after the : they will be put on the first line.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public class PlayerComponent extends Component {

public PlayerComponent(PlayerListEntry ple) {

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

this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.regex.Pattern;

/**
* Holds generic static constants
*/
public interface Constants {
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";
Pattern PLAYER_NAME = Pattern.compile("(?:\\[[0-9]+\\] )?(?:[" + Constants.LEVEL_EMBLEMS + "] )?(?:\\[[A-Z+]+\\] )?([A-Za-z0-9_]+)");

Supplier<MutableText> PREFIX = () -> {
LocalDate time = LocalDate.now();
Expand Down
Loading