Only replace the first instance of a name/nickname
This commit is contained in:
parent
7ef9b4a64a
commit
0c7ad69e85
|
|
@ -16,6 +16,7 @@ import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.PatternReplacementResult;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
@ -97,12 +98,20 @@ public class ChatListener implements Listener {
|
||||||
String name = onlinePlayer.getName();
|
String name = onlinePlayer.getName();
|
||||||
String nickName = PlainTextComponentSerializer.plainText().serialize(onlinePlayer.displayName());
|
String nickName = PlainTextComponentSerializer.plainText().serialize(onlinePlayer.displayName());
|
||||||
String message = modifiableString.string().toLowerCase();
|
String message = modifiableString.string().toLowerCase();
|
||||||
|
|
||||||
if (message.contains(name.toLowerCase())) {
|
if (message.contains(name.toLowerCase())) {
|
||||||
modifiableString.replace(Pattern.compile(name, Pattern.CASE_INSENSITIVE), mention.append(onlinePlayer.displayName()));
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
.once()
|
||||||
|
.match(Pattern.compile(name, Pattern.CASE_INSENSITIVE))
|
||||||
|
.replacement(mention.append(onlinePlayer.displayName()))
|
||||||
|
.build());
|
||||||
playerToPing.add(onlinePlayer);
|
playerToPing.add(onlinePlayer);
|
||||||
}
|
} else if (message.contains(nickName.toLowerCase())) {
|
||||||
if (!name.equalsIgnoreCase(nickName) && message.contains(nickName.toLowerCase())) {
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
modifiableString.replace(Pattern.compile(nickName, Pattern.CASE_INSENSITIVE), mention.append(onlinePlayer.displayName()));
|
.once()
|
||||||
|
.match(Pattern.compile(nickName, Pattern.CASE_INSENSITIVE))
|
||||||
|
.replacement(mention.append(onlinePlayer.displayName()))
|
||||||
|
.build());
|
||||||
playerToPing.add(onlinePlayer);
|
playerToPing.add(onlinePlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user