修复了菜单中称号前缀后缀未被解析问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m2s

This commit is contained in:
zhangyuheng 2024-07-01 01:40:28 +08:00
parent 25fe5fbb09
commit f5fe78f4d1
3 changed files with 6 additions and 9 deletions

View File

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

View File

@ -45,8 +45,7 @@ public class Expansion extends PlaceholderExpansion {
return ""; return "";
} }
TitleDTO t = title.getTitle(); TitleDTO t = title.getTitle();
return ChatColor.translateAlternateColorCodes('&', return ChatColor.translateAlternateColorCodes('&', t.getTitleColoredBukkit());
MiniPlayerTitle.config.getPrefix() + t.getTitleColoredBukkit() + MiniPlayerTitle.config.getSuffix());
} }
return null; // return null; //

View File

@ -74,11 +74,9 @@ public class TitleDTO {
} }
public TextComponent getTitleColored() { public TextComponent getTitleColored() {
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix()); String title = MiniPlayerTitle.config.getPrefix() + this.title + MiniPlayerTitle.config.getSuffix();
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix()); String[] parts = title.split("&#");
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;
@ -94,7 +92,6 @@ 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);
@ -110,7 +107,8 @@ public class TitleDTO {
* @return String * @return String
*/ */
public String getTitleColoredBukkit() { public String getTitleColoredBukkit() {
String title = this.title.replaceAll("&#", "#"); String title = MiniPlayerTitle.config.getPrefix() + this.title + MiniPlayerTitle.config.getSuffix();
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);
while (matcher.find()) { while (matcher.find()) {