blob: b527dc789180e883bc685f8fda7ba6502f8b8526 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package de.hysky.skyblocker.skyblock.tabhud.widget;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
// this widget shows a list of all people visiting the same private island as you
public class IslandGuestsWidget extends Widget {
private static final MutableText TITLE = Text.literal("Guests").formatted(Formatting.AQUA,
Formatting.BOLD);
// matches a player entry, removing their level and the hand icon
// group 1: player name
private static final Pattern GUEST_PATTERN = Pattern.compile("\\[\\d*\\] (.*) \\[.\\]");
public IslandGuestsWidget() {
super(TITLE, Formatting.AQUA.getColorValue());
}
@Override
public void updateContent() {
for (int i = 21; i < 40; i++) {
String str = PlayerListMgr.strAt(i);
if (str == null) {
if (i == 21) {
this.addComponent(new PlainTextComponent(Text.literal("No Visitors!").formatted(Formatting.GRAY)));
}
break;
}
Matcher m = PlayerListMgr.regexAt( i, GUEST_PATTERN);
if (m == null) {
this.addComponent(new PlainTextComponent(Text.of("???")));
} else {
this.addComponent(new PlainTextComponent(Text.of(m.group(1))));
}
}
}
}
|