Merge branch 'main' of https://github.com/Altitude-Devs/Chat
This commit is contained in:
commit
5398d97248
|
|
@ -87,7 +87,12 @@ public class ChatFilter {
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group(); // todo debug
|
String group = matcher.group(); // todo debug
|
||||||
if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/
|
if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/
|
||||||
modifiableString.replace(group, getReplacement());
|
modifiableString.replace(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.matchLiteral(group)
|
||||||
|
.replacement(getReplacement())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +108,10 @@ public class ChatFilter {
|
||||||
Matcher matcher = pattern.matcher(input);
|
Matcher matcher = pattern.matcher(input);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group();
|
String group = matcher.group();
|
||||||
modifiableString.replace(group, group.substring(0, length));
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
.matchLiteral(group)
|
||||||
|
.replacement(group.substring(0, length))
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,40 +19,8 @@ public class ModifiableString {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace(String match, String replace) {
|
public void replace(TextReplacementConfig textReplacementConfig) {
|
||||||
text = text
|
text = text.replaceText(textReplacementConfig);
|
||||||
.replaceText(
|
|
||||||
TextReplacementConfig.builder()
|
|
||||||
.matchLiteral(match)
|
|
||||||
.replacement(replace)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replace(Pattern match, String replace) {
|
|
||||||
text = text
|
|
||||||
.replaceText(
|
|
||||||
TextReplacementConfig.builder()
|
|
||||||
.match(match)
|
|
||||||
.replacement(replace)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replace(@RegExp String match, Component replace) {
|
|
||||||
text = text
|
|
||||||
.replaceText(
|
|
||||||
TextReplacementConfig.builder()
|
|
||||||
.matchLiteral(match)
|
|
||||||
.replacement(replace)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replace(Pattern match, Component replace) {
|
|
||||||
text = text
|
|
||||||
.replaceText(
|
|
||||||
TextReplacementConfig.builder()
|
|
||||||
.match(match)
|
|
||||||
.replacement(replace)
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String string() {
|
public String string() {
|
||||||
|
|
|
||||||
|
|
@ -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