Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-09-06 16:12:51 +02:00
Fixes #519
Use regex for finding colour codes Merge styles rather than replacing and undoing our work sometimes.
Dieser Commit ist enthalten in:
Ursprung
d92cded832
Commit
704e76eb6d
@ -5,6 +5,7 @@ import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.Style;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -16,9 +17,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Caption {
|
||||
|
||||
private static final Pattern colorCodes = Pattern.compile("&([0-9a-o])");
|
||||
|
||||
public static String toString(Component component) {
|
||||
return toString(component, WorldEdit.getInstance().getTranslationManager().getDefaultLocale());
|
||||
}
|
||||
@ -39,9 +44,9 @@ public class Caption {
|
||||
|
||||
private static Component color(TextComponent text) {
|
||||
String content = text.content();
|
||||
if (content.indexOf('&') != -1) {
|
||||
if (colorCodes.matcher(content).find()) {
|
||||
TextComponent legacy = LegacyComponentSerializer.INSTANCE.deserialize(content, '&');
|
||||
legacy = (TextComponent) legacy.style(text.style());
|
||||
legacy.style().merge(text.style(), Style.Merge.Strategy.IF_ABSENT_ON_TARGET);
|
||||
if (!text.children().isEmpty()) {
|
||||
text = TextComponent.builder().append(legacy).append(text.children()).build();
|
||||
} else {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren