Compare commits

..

No commits in common. "master" and "v4.6.2" have entirely different histories.

4 changed files with 65 additions and 10 deletions

View File

@ -1,4 +1,4 @@
<div align="center">
<div style="text-align: center;">
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%">

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId>
<version>4.7.0</version>
<version>4.6.2</version>
<packaging>jar</packaging>
<name>MiniPlayerTitle</name>
@ -82,7 +82,7 @@
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId>
<version>1.3.7-SNAPSHOT</version>
<version>1.3.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>

View File

@ -34,7 +34,7 @@ public class Expansion extends PlaceholderExpansion {
if (t == null) {
return "";
}
return t.getTitleColoredBukkit();
return ChatColor.translateAlternateColorCodes('&', t.getTitleColoredBukkit());
}
return null; //

View File

@ -1,16 +1,21 @@
package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.minecraftpluginutils.ColorParser;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.miniplayertitle.Color;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
@ -75,8 +80,32 @@ public class TitleDTO {
}
public TextComponent getTitleColored() {
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
return ColorParser.getComponentType(with_pre_suf);
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle());
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix(), new Color("#ffffff").getStyle());
String[] parts = getTitleRaw().split("&#");
List<TextComponent> components = new ArrayList<>();
components.add(prefix);
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
Color color = new Color("#ffffff");
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
String color_str = part.substring(0, 6);
color = new Color("#" + color_str);
content = part.substring(6);
} else {
content = part;
}
components.add(Component.text(content, color.getStyle()));
}
components.add(suffix);
TextComponent.Builder title_component = Component.text();
for (TextComponent component : components) {
title_component.append(component);
}
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(getDescription())));
}
/**
@ -87,12 +116,38 @@ public class TitleDTO {
* @return String
*/
public String getTitleColoredBukkit() {
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
return ColorParser.getBukkitType(with_pre_suf);
String title = "&f" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&f" + MiniPlayerTitle.config.getSuffix();
title = title.replaceAll("&#", "#");
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
Matcher matcher = pattern.matcher(title);
while (matcher.find()) {
String hexCode = matcher.group();
StringBuilder builder = new StringBuilder("&x");
for (char c : hexCode.substring(1).toCharArray()) {
builder.append('&').append(c);
}
title = title.replace(hexCode, builder.toString());
}
XLogger.debug("TitleDTO.getTitleColoredBukkit: %s", title);
return title;
}
public String getTitlePlainText() {
return ColorParser.getPlainText(getTitleRaw());
String[] parts = getTitleRaw().split("&#");
StringBuilder res = new StringBuilder();
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
String content;
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
content = part.substring(6);
} else {
content = part;
}
res.append(content);
}
return res.toString();
}
public Integer getId() {