From 3502c82b189d2f216a62504a1bff9962e4cb6fc0 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Wed, 12 Jul 2023 20:21:54 -0400 Subject: [PATCH 1/4] Fix ads filter to work with emblems --- .../java/me/xmrvizzy/skyblocker/chat/filters/AdFilter.java | 4 ++-- .../me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/AdFilter.java b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/AdFilter.java index 6773443884..6b681d4ca0 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/AdFilter.java +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/AdFilter.java @@ -18,8 +18,8 @@ public AdFilter() { // Groups: // 1. Player name // 2. Message - // (?:§8\[[§fadbc0-9]+§8\] )?§[67abc](?:\[[§A-Za-z0-9+]+\] )?([A-Za-z0-9_]+)§[f7]: (.+) - super("(?:§8\\[[§fadbc0-9]+§8\\] )?§[67abc](?:\\[[§A-Za-z0-9+]+\\] )?([A-Za-z0-9_]+)§[f7]: (.+)"); + // (?:§8\[[§feadbc0-9]+§8\] )?(?:.+ )?§[67abc](?:\[[§A-Za-z0-9+]+\] )?([A-Za-z0-9_]+)§[f7]: (.+) + super("(?:§8\\[[§feadbc0-9]+§8\\] )?(?:.+ )?§[67abc](?:\\[[§A-Za-z0-9+]+\\] )?([A-Za-z0-9_]+)§[f7]: (.+)"); } @Override diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java index a769dca2e3..8a776ab7cc 100644 --- a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java @@ -24,7 +24,7 @@ void vip() { @Test void mvp() { - assertMatches("§8[§d256§8] §b[MVP§c+§b] Advertiser§f: advertisement"); + assertMatches("§8[§d256§8] §6§l⚡ §b[MVP§c+§b] Advertiser§f: advertisement"); } @Test @@ -39,7 +39,7 @@ void capturesMessage() { @Test void simpleAd() { - assertFilters("§8[§c320§8] §b[MVP§c+§b] b2dderr§f: buying prismapump"); + assertFilters("§8[§e320§8] §b[MVP§c+§b] b2dderr§f: buying prismapump"); } @Test From 2243d4035b522cc872393801edea7600be84ad05 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Thu, 13 Jul 2023 01:10:06 -0400 Subject: [PATCH 2/4] Fix rank prefixes and emblems showing in some player lists --- .../skyblock/tabhud/widget/DungeonPlayerWidget.java | 6 +++--- .../skyblock/tabhud/widget/IslandOwnersWidget.java | 3 ++- .../skyblock/tabhud/widget/IslandSelfWidget.java | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonPlayerWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonPlayerWidget.java index c1f9e235e4..443cca558f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonPlayerWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonPlayerWidget.java @@ -25,10 +25,10 @@ public class DungeonPlayerWidget extends Widget { // group 1: name // group 2: class (or literal "EMPTY" pre dungeon start) // group 3: level (or nothing, if pre dungeon start) - // as a side effect, this regex keeps the iron man icon in the name - // not sure if that should be + // this regex filters out the ironman icon as well as rank prefixes and emblems + // \[\d*\] (?:\[[A-Za-z]+\] )?(?[A-Za-z0-9_]*) (?:.* )?\((?\S*) ?(?[LXVI]*)\) private static final Pattern PLAYER_PATTERN = Pattern - .compile("\\[\\d*\\] (?.*) \\((?\\S*) ?(?[LXVI]*)\\)"); + .compile("\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?(?[A-Za-z0-9_]*) (?:.* )?\\((?\\S*) ?(?[LXVI]*)\\)"); private static final HashMap ICOS = new HashMap<>(); private static final ArrayList MSGS = new ArrayList<>(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java index 6c2d6b4754..e81a6d8579 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandOwnersWidget.java @@ -20,8 +20,9 @@ public class IslandOwnersWidget extends Widget { // matches an owner // group 1: player name // group 2: last seen, if owner not online + // ^(?.*) \((?.*)\)$|^\[\d*\] (?:\[[A-Za-z]+\] )?(?[A-Za-z0-9_]*)(?: .*)?$|^(?.*)$ private static final Pattern OWNER_PATTERN = Pattern - .compile("^(?.*) \\((?.*)\\)$|^\\[\\d*\\] (?.*)$|^(?.*)$"); + .compile("^(?.*) \\((?.*)\\)$|^\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?(?[A-Za-z0-9_]*)(?: .*)?$|^(?.*)$"); public IslandOwnersWidget() { super(TITLE, Formatting.DARK_PURPLE.getColorValue()); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java index 4324dad9bd..45cad6c3a4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java @@ -19,7 +19,8 @@ public class IslandSelfWidget extends Widget { // matches an owner // group 1: player name, optionally offline time - private static final Pattern OWNER_PATTERN = Pattern.compile("^\\[\\d*\\] (.*)$|^(.*)$"); + // ^\[\d*\] (?:\[[A-Za-z]+\] )?([A-Za-z0-9_() ]*)(?: .*)?$|^(.*)$ + private static final Pattern OWNER_PATTERN = Pattern.compile("^\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?([A-Za-z0-9_() ]*)(?: .*)?$|^(.*)$"); public IslandSelfWidget() { super(TITLE, Formatting.DARK_PURPLE.getColorValue()); @@ -28,7 +29,9 @@ public IslandSelfWidget() { if (m == null) { break; } - PlainTextComponent ptc = new PlainTextComponent(Text.of(m.group(1))); + + Text entry = (m.group(1) != null) ? Text.of(m.group(1)) : Text.of(m.group(2)); + PlainTextComponent ptc = new PlainTextComponent(entry); this.addComponent(ptc); } this.pack(); From aa7c7329d4d10f5b1c8c30acb1181a3df7e68404 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Thu, 13 Jul 2023 01:54:10 -0400 Subject: [PATCH 3/4] Format player names in the players widget --- .../skyblocker/config/SkyblockerConfig.java | 19 +++++++++++++++++++ .../tabhud/widget/PlayerListWidget.java | 17 ++++++++++------- .../widget/component/PlayerComponent.java | 12 ++++++++++-- .../assets/skyblocker/lang/en_us.json | 4 ++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index bd616c2c23..04cfaea35f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -188,6 +188,25 @@ public static class TabHudConf { @ConfigEntry.BoundedDiscrete(min = 10, max = 200) @ConfigEntry.Gui.Tooltip() public int tabHudScale = 100; + @ConfigEntry.Gui.Tooltip + public boolean plainPlayerNames = false; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @ConfigEntry.Gui.Tooltip + public NameSorting nameSorting = NameSorting.DEFAULT; + + } + + public enum NameSorting { + DEFAULT, + ALPHABETICAL; + + @Override + public String toString() { + return switch (this) { + case DEFAULT -> "Default"; + case ALPHABETICAL -> "Alphabetical"; + }; + } } public static class Bars { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java index 2cd710eb71..0f0d1fa91e 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.Comparator; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerListMgr; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.PlayerComponent; @@ -48,13 +49,15 @@ public PlayerListWidget() { for (int i = 80; i < listlen; i++) { list.add(PlayerListMgr.getRaw(i)); } - - Collections.sort(list, new Comparator() { - @Override - public int compare(PlayerListEntry o1, PlayerListEntry o2) { - return o1.getProfile().getName().toLowerCase().compareTo(o2.getProfile().getName().toLowerCase()); - } - }); + + if (SkyblockerConfig.get().general.tabHud.nameSorting == SkyblockerConfig.NameSorting.ALPHABETICAL) { + Collections.sort(list, new Comparator() { + @Override + public int compare(PlayerListEntry o1, PlayerListEntry o2) { + return o1.getProfile().getName().toLowerCase().compareTo(o2.getProfile().getName().toLowerCase()); + } + }); + } int x = 0, y = 0; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java index fd66ec73fb..32058e26c8 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java @@ -1,8 +1,11 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.PlayerSkinDrawer; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.scoreboard.Team; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; /** @@ -12,12 +15,17 @@ public class PlayerComponent extends Component { private static final int SKIN_ICO_DIM = 8; - private String name; + private Text name; private Identifier tex; public PlayerComponent(PlayerListEntry ple) { + + boolean plainNames = SkyblockerConfig.get().general.tabHud.plainPlayerNames; + Team team = ple.getScoreboardTeam(); + String username = ple.getProfile().getName(); + Text displayName = (team != null && !plainNames) ? Text.empty().append(team.getPrefix()).append(Text.literal(username).formatted(team.getColor())).append(team.getSuffix()) : Text.of(username); - name = ple.getProfile().getName(); + name = displayName; tex = ple.getSkinTexture(); this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 9dc2a856de..0cf9933cd2 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -36,6 +36,10 @@ "text.autoconfig.skyblocker.option.general.tabHud.tabHudEnabled": "Enable fancy tab HUD", "text.autoconfig.skyblocker.option.general.tabHud.tabHudScale": "Scale factor of fancy tab HUD", "text.autoconfig.skyblocker.option.general.tabHud.tabHudScale.@Tooltip": "Value in %, relative to your vanilla GUI scale", + "text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames": "Plain Player Names", + "text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames.@Tooltip":"Enable to display player names without any special formatting on public islands.", + "text.autoconfig.skyblocker.option.general.tabHud.nameSorting": "Player Name Sorting Method", + "text.autoconfig.skyblocker.option.general.tabHud.nameSorting.@Tooltip": "Alphabetical sorting sorts names alphabetically while Default has no particular order.", "text.autoconfig.skyblocker.option.general.itemTooltip": "Item Tooltip", "text.autoconfig.skyblocker.option.general.itemTooltip.enableNPCPrice": "Enable NPC Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableMotesPrice": "Enable Motes Price", From 65c0b0c57e4f1fb888fbd1bde97b0929d663e50b Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Fri, 14 Jul 2023 09:37:27 +0800 Subject: [PATCH 4/4] Refactor player widgets --- .../tabhud/widget/IslandSelfWidget.java | 3 +-- .../tabhud/widget/PlayerListWidget.java | 22 ++++++------------- .../widget/component/PlayerComponent.java | 8 +++---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java index 45cad6c3a4..4b03da6e29 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/IslandSelfWidget.java @@ -31,8 +31,7 @@ public IslandSelfWidget() { } Text entry = (m.group(1) != null) ? Text.of(m.group(1)) : Text.of(m.group(2)); - PlainTextComponent ptc = new PlainTextComponent(entry); - this.addComponent(ptc); + this.addComponent(new PlainTextComponent(entry)); } this.pack(); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java index 0f0d1fa91e..439fcb569a 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/PlayerListWidget.java @@ -1,20 +1,18 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.widget; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerListMgr; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.PlayerComponent; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component.TableComponent; - import net.minecraft.client.network.PlayerListEntry; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import java.util.ArrayList; +import java.util.Comparator; + // this widget shows a list of players with their skins. // responsible for non-private-island areas @@ -23,7 +21,7 @@ public class PlayerListWidget extends Widget { private static final MutableText TITLE = Text.literal("Players").formatted(Formatting.GREEN, Formatting.BOLD); - private ArrayList list = new ArrayList<>(); + private final ArrayList list = new ArrayList<>(); public PlayerListWidget() { super(TITLE, Formatting.GREEN.getColorValue()); @@ -43,20 +41,14 @@ public PlayerListWidget() { // https://stackoverflow.com/questions/7139382/java-rounding-up-to-an-int-using-math-ceil#21830188 int tblW = ((listlen - 80) - 1) / 20 + 1; - TableComponent tc = new TableComponent(tblW, (listlen - 80 >= 20) ? 20 : listlen - 80, - Formatting.GREEN.getColorValue()); + TableComponent tc = new TableComponent(tblW, Math.min(listlen - 80, 20), Formatting.GREEN.getColorValue()); for (int i = 80; i < listlen; i++) { list.add(PlayerListMgr.getRaw(i)); } - + if (SkyblockerConfig.get().general.tabHud.nameSorting == SkyblockerConfig.NameSorting.ALPHABETICAL) { - Collections.sort(list, new Comparator() { - @Override - public int compare(PlayerListEntry o1, PlayerListEntry o2) { - return o1.getProfile().getName().toLowerCase().compareTo(o2.getProfile().getName().toLowerCase()); - } - }); + list.sort(Comparator.comparing(o -> o.getProfile().getName().toLowerCase())); } int x = 0, y = 0; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java index 32058e26c8..1be6adda88 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java @@ -15,17 +15,15 @@ public class PlayerComponent extends Component { private static final int SKIN_ICO_DIM = 8; - private Text name; - private Identifier tex; + private final Text name; + private final Identifier tex; public PlayerComponent(PlayerListEntry ple) { boolean plainNames = SkyblockerConfig.get().general.tabHud.plainPlayerNames; Team team = ple.getScoreboardTeam(); String username = ple.getProfile().getName(); - Text displayName = (team != null && !plainNames) ? Text.empty().append(team.getPrefix()).append(Text.literal(username).formatted(team.getColor())).append(team.getSuffix()) : Text.of(username); - - name = displayName; + name = (team != null && !plainNames) ? Text.empty().append(team.getPrefix()).append(Text.literal(username).formatted(team.getColor())).append(team.getSuffix()) : Text.of(username); tex = ple.getSkinTexture(); this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);