修复了菜单中称号前缀后缀未被解析问题
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>
<artifactId>MiniPlayerTitle</artifactId>
<version>4.2.4</version>
<version>4.2.5</version>
<packaging>jar</packaging>
<name>MiniPlayerTitle</name>

View File

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

View File

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