Added a way to replace text with components and patterns with strings/components
This commit is contained in:
parent
e811b0ca9a
commit
6beb398e10
|
|
@ -3,6 +3,10 @@ package com.alttd.chat.objects;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.intellij.lang.annotations.RegExp;
|
||||||
|
|
||||||
|
import javax.annotation.RegEx;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ModifiableString {
|
public class ModifiableString {
|
||||||
private Component text;
|
private Component text;
|
||||||
|
|
@ -24,6 +28,33 @@ public class ModifiableString {
|
||||||
.build());
|
.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() {
|
||||||
return PlainTextComponentSerializer.plainText().serialize(text);
|
return PlainTextComponentSerializer.plainText().serialize(text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user