Fix ChatFilter.java not applying to message.

This commit is contained in:
Len
2022-10-08 11:05:56 +02:00
parent 5db22461cf
commit 3aa0b09133
6 changed files with 91 additions and 56 deletions
@@ -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;
}
}