This commit is contained in:
parent
8ef1c9a7d0
commit
c4d25b79cf
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>MiniPlayerTitle</artifactId>
|
<artifactId>MiniPlayerTitle</artifactId>
|
||||||
<version>4.1.0</version>
|
<version>4.2.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>MiniPlayerTitle</name>
|
<name>MiniPlayerTitle</name>
|
||||||
|
@ -6,6 +6,7 @@ import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
|
|||||||
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -43,7 +44,8 @@ public class Expansion extends PlaceholderExpansion {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
TitleDTO t = title.getTitle();
|
TitleDTO t = title.getTitle();
|
||||||
return MiniPlayerTitle.config.getPrefix() + t.getTitlePlainText() + MiniPlayerTitle.config.getSuffix();
|
return ChatColor.translateAlternateColorCodes('&',
|
||||||
|
MiniPlayerTitle.config.getPrefix() + t.getTitleColoredBukkit() + MiniPlayerTitle.config.getSuffix());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; //
|
return null; //
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package cn.lunadeer.miniplayertitle.dtos;
|
package cn.lunadeer.miniplayertitle.dtos;
|
||||||
|
|
||||||
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||||
import cn.lunadeer.miniplayertitle.Color;
|
import cn.lunadeer.miniplayertitle.Color;
|
||||||
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TitleDTO {
|
public class TitleDTO {
|
||||||
private int id;
|
private int id;
|
||||||
@ -80,7 +84,6 @@ public class TitleDTO {
|
|||||||
if (part.isEmpty()) {
|
if (part.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// match hex regx ^[0-9a-fA-F]{6}$
|
|
||||||
Color color = new Color("#ffffff");
|
Color color = new Color("#ffffff");
|
||||||
String content;
|
String content;
|
||||||
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
|
if (part.length() > 6 && part.substring(0, 6).matches("^[0-9a-fA-F]{6}$")) {
|
||||||
@ -100,6 +103,29 @@ public class TitleDTO {
|
|||||||
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(this.description)));
|
return title_component.build().hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text(this.description)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取称号的颜色化字符串
|
||||||
|
* 需要使用 translateAlternateColorCodes 方法对返回字符串进行处理
|
||||||
|
* &#FFFFFF -> &x&f&f&f&f&f
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getTitleColoredBukkit() {
|
||||||
|
String title = this.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() {
|
public String getTitlePlainText() {
|
||||||
String[] parts = this.title.split("&#");
|
String[] parts = this.title.split("&#");
|
||||||
StringBuilder res = new StringBuilder();
|
StringBuilder res = new StringBuilder();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.lunadeer.miniplayertitle.tuis;
|
package cn.lunadeer.miniplayertitle.tuis;
|
||||||
|
|
||||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.VaultConnect;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||||
@ -24,8 +25,14 @@ public class Menu {
|
|||||||
Notification.error(player, "获取玩家信息时出现错误");
|
Notification.error(player, "获取玩家信息时出现错误");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Line balance = Line.create()
|
Line balance;
|
||||||
.append("称号币余额: ").append(playerInfo.getCoin().toString());
|
if (!MiniPlayerTitle.config.isExternalEco()) {
|
||||||
|
balance = Line.create()
|
||||||
|
.append("称号币余额: ").append(playerInfo.getCoin().toString());
|
||||||
|
} else {
|
||||||
|
balance = Line.create()
|
||||||
|
.append("余额: ").append(playerInfo.getCoin().toString()).append(VaultConnect.instance.currencyNamePlural());
|
||||||
|
}
|
||||||
Line backpack = Line.create()
|
Line backpack = Line.create()
|
||||||
.append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号");
|
.append(Button.create("称号背包").setExecuteCommand("/mplt my_titles").build()).append("查看你拥有的称号");
|
||||||
Line shop = Line.create()
|
Line shop = Line.create()
|
||||||
|
Loading…
Reference in New Issue
Block a user