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

Skyblock Levels fixes + Tab Hud improvements #201

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 @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]+\] )?(?<name>[A-Za-z0-9_]*) (?:.* )?\((?<class>\S*) ?(?<level>[LXVI]*)\)
private static final Pattern PLAYER_PATTERN = Pattern
.compile("\\[\\d*\\] (?<name>.*) \\((?<class>\\S*) ?(?<level>[LXVI]*)\\)");
.compile("\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?(?<name>[A-Za-z0-9_]*) (?:.* )?\\((?<class>\\S*) ?(?<level>[LXVI]*)\\)");

private static final HashMap<String, ItemStack> ICOS = new HashMap<>();
private static final ArrayList<String> MSGS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class IslandOwnersWidget extends Widget {
// matches an owner
// group 1: player name
// group 2: last seen, if owner not online
// ^(?<nameA>.*) \((?<lastseen>.*)\)$|^\[\d*\] (?:\[[A-Za-z]+\] )?(?<nameB>[A-Za-z0-9_]*)(?: .*)?$|^(?<nameC>.*)$
private static final Pattern OWNER_PATTERN = Pattern
.compile("^(?<nameA>.*) \\((?<lastseen>.*)\\)$|^\\[\\d*\\] (?<nameB>.*)$|^(?<nameC>.*)$");
.compile("^(?<nameA>.*) \\((?<lastseen>.*)\\)$|^\\[\\d*\\] (?:\\[[A-Za-z]+\\] )?(?<nameB>[A-Za-z0-9_]*)(?: .*)?$|^(?<nameC>.*)$");

public IslandOwnersWidget() {
super(TITLE, Formatting.DARK_PURPLE.getColorValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -28,8 +29,9 @@ public IslandSelfWidget() {
if (m == null) {
break;
}
PlainTextComponent ptc = new PlainTextComponent(Text.of(m.group(1)));
this.addComponent(ptc);

Text entry = (m.group(1) != null) ? Text.of(m.group(1)) : Text.of(m.group(2));
this.addComponent(new PlainTextComponent(entry));
}
this.pack();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +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

Expand All @@ -22,7 +21,7 @@ public class PlayerListWidget extends Widget {
private static final MutableText TITLE = Text.literal("Players").formatted(Formatting.GREEN,
Formatting.BOLD);

private ArrayList<PlayerListEntry> list = new ArrayList<>();
private final ArrayList<PlayerListEntry> list = new ArrayList<>();

public PlayerListWidget() {
super(TITLE, Formatting.GREEN.getColorValue());
Expand All @@ -42,19 +41,15 @@ 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));
}

Collections.sort(list, new Comparator<PlayerListEntry>() {
@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) {
list.sort(Comparator.comparing(o -> o.getProfile().getName().toLowerCase()));
}

int x = 0, y = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -12,12 +15,15 @@ public class PlayerComponent extends Component {

private static final int SKIN_ICO_DIM = 8;

private String name;
private Identifier tex;
private final Text name;
private final Identifier tex;

public PlayerComponent(PlayerListEntry ple) {

name = ple.getProfile().getName();

boolean plainNames = SkyblockerConfig.get().general.tabHud.plainPlayerNames;
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);
tex = ple.getSkinTexture();

this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down