修复了称号前后缀颜色不定问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m1s

This commit is contained in:
zhangyuheng 2024-07-01 10:51:06 +08:00
parent f5fe78f4d1
commit ddf5ae711a
2 changed files with 7 additions and 4 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId> <artifactId>MiniPlayerTitle</artifactId>
<version>4.2.5</version> <version>4.2.6</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>MiniPlayerTitle</name> <name>MiniPlayerTitle</name>

View File

@ -74,9 +74,11 @@ public class TitleDTO {
} }
public TextComponent getTitleColored() { public TextComponent getTitleColored() {
String title = MiniPlayerTitle.config.getPrefix() + this.title + MiniPlayerTitle.config.getSuffix(); TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle());
String[] parts = title.split("&#"); TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix(), new Color("#ffffff").getStyle());
String[] parts = this.title.split("&#");
List<TextComponent> components = new ArrayList<>(); List<TextComponent> components = new ArrayList<>();
components.add(prefix);
for (String part : parts) { for (String part : parts) {
if (part.isEmpty()) { if (part.isEmpty()) {
continue; continue;
@ -92,6 +94,7 @@ public class TitleDTO {
} }
components.add(Component.text(content, color.getStyle())); components.add(Component.text(content, color.getStyle()));
} }
components.add(suffix);
TextComponent.Builder title_component = Component.text(); TextComponent.Builder title_component = Component.text();
for (TextComponent component : components) { for (TextComponent component : components) {
title_component.append(component); title_component.append(component);
@ -107,7 +110,7 @@ public class TitleDTO {
* @return String * @return String
*/ */
public String getTitleColoredBukkit() { public String getTitleColoredBukkit() {
String title = MiniPlayerTitle.config.getPrefix() + this.title + MiniPlayerTitle.config.getSuffix(); String title = "&f" + MiniPlayerTitle.config.getPrefix() + this.title + "&f" + MiniPlayerTitle.config.getSuffix();
title = title.replaceAll("&#", "#"); title = title.replaceAll("&#", "#");
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
Matcher matcher = pattern.matcher(title); Matcher matcher = pattern.matcher(title);