Skip to content
Open
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 @@ -93,7 +93,6 @@ public boolean replaceUsername(

int next = text.indexOf(playerName);
if (next != -1) {
replaced = true;
int length = text.length();
if (next == 0) {
if (length == playerName.length()) {
Expand All @@ -116,12 +115,12 @@ public boolean replaceUsername(
// Replace the name multiple times in the same text component
next = text.indexOf(playerName, nameEndsAt);

// Skip when player name is not at the start and the character in front of name is a space
// Skip when player name is not at the start and the character in front of name is not a space
if (i != 0 && text.charAt(i - 1) != ' ') {
continue;
}

// Skip when player name is not at the end and the character after the name is a space
// Skip when player name is not at the end and the character after the name is not a space
if (nameEndsAt < length && text.charAt(nameEndsAt) != ' ') {
continue;
}
Expand All @@ -130,6 +129,7 @@ public boolean replaceUsername(
component.append(childIndex++, Component.text(text.substring(lastNameAt, i)));
}

replaced = true;
component.append(childIndex++, customName.get());
lastNameAt = nameEndsAt;

Expand All @@ -154,7 +154,6 @@ public Component replaceLegacyContext(Component component) {
for (Component child : component.getChildren()) {
children.add(this.replaceLegacyContext(child));
}
component.setChildren(children);

if (component instanceof TranslatableComponent translatableComponent) {
List<Component> arguments = new ArrayList<>();
Expand All @@ -171,9 +170,17 @@ public Component replaceLegacyContext(Component component) {
Style style = component.style();
component = LegacyComponentSerializer.legacySection().deserialize(text);
component.style(component.style().merge(style, Strategy.IF_ABSENT_ON_TARGET));

for (Component child : children) {
component.append(child);
}

return component;
}
}

component.setChildren(children);

return component;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import net.labymod.addons.customnametags.CustomNameTag;
import net.labymod.addons.customnametags.CustomNameTags;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.TextComponent;
import net.labymod.api.client.component.TranslatableComponent;
import net.labymod.api.client.component.serializer.legacy.LegacyComponentSerializer;
import net.labymod.api.event.Priority;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.chat.ChatReceiveEvent;
Expand Down