Fix ChatFilter.java not applying to message.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -47,7 +52,13 @@ public class ChatFilter {
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find())
|
||||
if (!isException(input, matcher.start())) {
|
||||
filterableString.string(filterableString.string().replaceFirst(matcher.group(), "<gold>" + matcher.group() + "</gold>"));
|
||||
// filterableString.string(filterableString.string().replaceFirst(matcher.group(), "<gold>" + matcher.group() + "</gold>"));
|
||||
filterableString.string(filterableString.component()
|
||||
.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.match(matcher.pattern())
|
||||
.replacement(Component.text(matcher.group()).style(Style.style(NamedTextColor.GOLD)))
|
||||
.build()));
|
||||
return true;
|
||||
}
|
||||
return matcher.matches();
|
||||
|
||||
@@ -1,22 +1,34 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
public class ModifiableString {
|
||||
private String string;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public ModifiableString(String string) {
|
||||
this.string = string;
|
||||
public class ModifiableString {
|
||||
private Component text;
|
||||
|
||||
public ModifiableString(Component text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void string(String string) {
|
||||
this.string = string;
|
||||
public void string(Component text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void replace(String match, String replace) {
|
||||
while (string.contains(match))
|
||||
string = string.replace(match, replace);
|
||||
text = text
|
||||
.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.matchLiteral(match)
|
||||
.replacement(replace)
|
||||
.build());
|
||||
}
|
||||
|
||||
public String string() {
|
||||
return string;
|
||||
return PlainTextComponentSerializer.plainText().serialize(text);
|
||||
}
|
||||
|
||||
public Component component() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user