Compare commits

..

7 Commits

Author SHA1 Message Date
40e561bff1 修复了在spigot相关核心下无法连接papi的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 15m20s
2024-09-29 00:31:18 +08:00
11856a29a6 更新 README.md 2024-08-19 10:36:18 +08:00
78de7dca65 支持渐变语法
All checks were successful
Java CI-CD with Maven / build (push) Successful in 10m56s
2024-08-12 16:42:54 +08:00
466dd84fac 修复称号卡可能会被用于其他物品的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 21m27s
2024-07-26 17:48:12 +08:00
283e435b70 增加生成称号卡时的逻辑检查
All checks were successful
Java CI-CD with Maven / build (push) Successful in 18m48s
2024-07-26 17:23:35 +08:00
2981ac0183 新增称号卡支持
All checks were successful
Java CI-CD with Maven / build (push) Successful in 25m27s
2024-07-26 17:16:52 +08:00
02d44610c6 新增对VaultUnlocked支持
All checks were successful
Java CI-CD with Maven / build (push) Successful in 9m50s
2024-07-21 14:57:00 +08:00
12 changed files with 160 additions and 72 deletions

View File

@ -1,4 +1,4 @@
<div style="text-align: center;"> <div align="center">
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604de7db2e6f.png" alt="" width="70%"> <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> <groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId> <artifactId>MiniPlayerTitle</artifactId>
<version>4.4.0</version> <version>4.7.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>MiniPlayerTitle</name> <name>MiniPlayerTitle</name>
@ -82,7 +82,7 @@
<dependency> <dependency>
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId> <artifactId>MinecraftPluginUtils</artifactId>
<version>1.3.4-SNAPSHOT</version> <version>1.3.7-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>

View File

@ -1,6 +1,7 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle;
import cn.lunadeer.miniplayertitle.commands.PlayerManage; import cn.lunadeer.miniplayertitle.commands.PlayerManage;
import cn.lunadeer.miniplayertitle.commands.TitleCard;
import cn.lunadeer.miniplayertitle.commands.TitleManage; import cn.lunadeer.miniplayertitle.commands.TitleManage;
import cn.lunadeer.miniplayertitle.commands.TitleShopSale; import cn.lunadeer.miniplayertitle.commands.TitleShopSale;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
@ -81,6 +82,9 @@ public class Commands implements TabExecutor {
case "grant_title": // mplt grant_title <玩家名称> <称号> <描述> [天数] case "grant_title": // mplt grant_title <玩家名称> <称号> <描述> [天数]
PlayerManage.grantTitle(sender, args); PlayerManage.grantTitle(sender, args);
break; break;
case "get_card": // mplt get_card <商品ID>
TitleCard.getTitleCard(sender, args);
break;
default: default:
return false; return false;
} }
@ -93,7 +97,7 @@ public class Commands implements TabExecutor {
return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info", return Arrays.asList("menu", "all_titles", "my_titles", "shop", "custom_info", "sale_info",
"create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title", "create_sale", "set_sale", "delete_sale", "buy_sale", "use_title", "create_title",
"delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin", "delete_title", "edit_title_name", "edit_title_desc", "custom_title", "add_coin", "set_coin",
"grant_title" "grant_title", "get_card"
); );
} }
if (args.length == 2) { if (args.length == 2) {
@ -101,6 +105,7 @@ public class Commands implements TabExecutor {
case "sale_info": case "sale_info":
case "delete_sale": case "delete_sale":
case "buy_sale": case "buy_sale":
case "get_card":
return Collections.singletonList("<商品ID>"); return Collections.singletonList("<商品ID>");
case "create_sale": case "create_sale":
case "delete_title": case "delete_title":

View File

@ -34,7 +34,7 @@ public class Expansion extends PlaceholderExpansion {
if (t == null) { if (t == null) {
return ""; return "";
} }
return ChatColor.translateAlternateColorCodes('&', t.getTitleColoredBukkit()); return t.getTitleColoredBukkit();
} }
return null; // return null; //
@ -52,6 +52,6 @@ public class Expansion extends PlaceholderExpansion {
@Override @Override
public @NotNull String getVersion() { public @NotNull String getVersion() {
return plugin.getPluginMeta().getVersion(); return MiniPlayerTitle.instance.getDescription().getVersion();
} }
} }

View File

@ -1,8 +1,10 @@
package cn.lunadeer.miniplayertitle; package cn.lunadeer.miniplayertitle;
import cn.lunadeer.minecraftpluginutils.*; import cn.lunadeer.minecraftpluginutils.*;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseType; import cn.lunadeer.minecraftpluginutils.databse.DatabaseType;
import cn.lunadeer.miniplayertitle.commands.TitleCard;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.events.Events; import cn.lunadeer.miniplayertitle.events.Events;
import cn.lunadeer.miniplayertitle.events.PaperChat; import cn.lunadeer.miniplayertitle.events.PaperChat;
@ -46,6 +48,7 @@ public final class MiniPlayerTitle extends JavaPlugin {
} }
Bukkit.getPluginManager().registerEvents(new Events(), this); Bukkit.getPluginManager().registerEvents(new Events(), this);
Bukkit.getPluginManager().registerEvents(new TitleCard(), this);
if (Common.isPaper()) { if (Common.isPaper()) {
Bukkit.getPluginManager().registerEvents(new PaperChat(), this); Bukkit.getPluginManager().registerEvents(new PaperChat(), this);
} else { } else {

View File

@ -0,0 +1,135 @@
package cn.lunadeer.miniplayertitle.commands;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class TitleCard implements Listener {
public static void getTitleCard(CommandSender sender, String[] args) {
try {
if (!sender.hasPermission("mplt.admin")) return;
if (!(sender instanceof Player)) {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (args.length != 2) {
Notification.warn(sender, "用法: /mplt get_card <销售ID>");
return;
}
int saleId = Integer.parseInt(args[1]);
TitleShopDTO titleShop = TitleShopDTO.get(saleId);
if (titleShop == null) {
Notification.error(sender, "获取销售详情时出现错误");
return;
}
if (titleShop.getDays() == 0) {
Notification.error(sender, "不可以生成天数为0的称号卡");
return;
}
ItemStack card = TitleCard.create(titleShop);
Player player = (Player) sender;
player.getInventory().addItem(card);
Notification.info(player, "成功创建称号卡");
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
@EventHandler
public void useTitleCard(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (player.getInventory().getItemInMainHand().getType() != Material.NAME_TAG) {
return;
}
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getItemMeta() == null || item.getItemMeta().getLore() == null || item.getItemMeta().getLore().size() != 5) {
return;
}
use(player, item);
player.getInventory().removeItem(item);
event.setCancelled(true);
}
private static ItemStack create(@NotNull TitleShopDTO saleInfo) {
ItemStack card = new ItemStack(Material.NAME_TAG);
TitleDTO title = saleInfo.getTitle();
card.editMeta(meta -> {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', title.getTitleColoredBukkit()));
meta.setLore(
Arrays.asList(
"称号ID: " + title.getId(),
"使用后获得天数: " + (saleInfo.getDays() == -1 ? "永久" : saleInfo.getDays()),
"称号描述: " + title.getDescription(),
"",
ChatColor.GRAY + "【右键使用】"
)
);
});
return card;
}
private static void use(@NotNull Player player, @NotNull ItemStack item) {
try {
if (item.getType() != Material.NAME_TAG) {
return;
}
List<String> lore = item.getLore();
if (lore == null || lore.size() != 5) {
return;
}
int titleId = Integer.parseInt(lore.get(0).split(": ")[1]);
int day = lore.get(1).split(": ")[1].equals("永久") ? -1 : Integer.parseInt(lore.get(1).split(": ")[1]);
List<PlayerTitleDTO> playerTitles = PlayerTitleDTO.getAllOf(player.getUniqueId());
PlayerTitleDTO had = null;
for (PlayerTitleDTO playerTitle : playerTitles) {
if (Objects.equals(playerTitle.getTitle().getId(), titleId)) {
had = playerTitle;
break;
}
}
TitleDTO title = TitleDTO.get(titleId);
if (title == null) {
Notification.error(player, "称号不存在");
return;
}
if (had == null) {
had = PlayerTitleDTO.create(player.getUniqueId(), title, day == -1 ? null : LocalDateTime.now().plusDays(day));
if (had == null) {
Notification.error(player, "购买称号时出现错误,详情请查看控制台日志");
return;
}
Notification.info(player, Component.text("成功使用称号卡: ").append(had.getTitle().getTitleColored()));
} else if (!had.isExpired()) {
Notification.warn(player, "你已拥有此称号,在过期前无法使用称号卡");
} else {
had.setExpireAt(day == -1 ? null : LocalDateTime.now().plusDays(day));
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
}
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
} catch (Exception e) {
Notification.error(player, "使用称号卡时出现错误: %s", e.getMessage());
}
}
}

View File

@ -194,6 +194,7 @@ public class TitleShopSale {
Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored())); Notification.info(player, Component.text("成功续续期称号: ").append(had.getTitle().getTitleColored()));
} }
TitleManage.useTitle(player, new String[]{"use_title", String.valueOf(had.getId())});
int page = getArgPage(args, 3); int page = getArgPage(args, 3);
MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)}); MyTitles.show(sender, new String[]{"my_titles", String.valueOf(page)});
} }

View File

@ -1,6 +1,6 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.minecraftpluginutils.VaultConnect; import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field; import cn.lunadeer.minecraftpluginutils.databse.Field;

View File

@ -1,21 +1,16 @@
package cn.lunadeer.miniplayertitle.dtos; package cn.lunadeer.miniplayertitle.dtos;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.ColorParser;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field; import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType; import cn.lunadeer.minecraftpluginutils.databse.FieldType;
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.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
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;
import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError; import static cn.lunadeer.minecraftpluginutils.databse.DatabaseManager.handleDatabaseError;
@ -80,74 +75,24 @@ public class TitleDTO {
} }
public TextComponent getTitleColored() { public TextComponent getTitleColored() {
TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle()); String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
TextComponent suffix = Component.text(MiniPlayerTitle.config.getSuffix(), new Color("#ffffff").getStyle()); return ColorParser.getComponentType(with_pre_suf);
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())));
} }
/** /**
* 获取称号的颜色化字符串 * 获取称号的颜色化字符串
* 需要使用 translateAlternateColorCodes 方法对返回字符串进行处理 * 需要使用 ChatColor.translateAlternateColorCodes 方法对返回字符串进行处理
* &#FFFFFF -> &x&f&f&f&f&f * &#FFFFFF -> &x&f&f&f&f&f
* *
* @return String * @return String
*/ */
public String getTitleColoredBukkit() { public String getTitleColoredBukkit() {
String title = "&f" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&f" + MiniPlayerTitle.config.getSuffix(); String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix();
title = title.replaceAll("&#", "#"); return ColorParser.getBukkitType(with_pre_suf);
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 = getTitleRaw().split("&#"); return ColorParser.getPlainText(getTitleRaw());
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() { public Integer getId() {

View File

@ -1,8 +1,6 @@
package cn.lunadeer.miniplayertitle.events; package cn.lunadeer.miniplayertitle.events;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.MiniPlayerTitle; import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import net.kyori.adventure.text.Component;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;

View File

@ -1,7 +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.VaultConnect.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;

View File

@ -122,6 +122,7 @@ public class SaleInfo {
} }
if (player.hasPermission("mplt.admin")) { if (player.hasPermission("mplt.admin")) {
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build()); operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
operate.append(Button.createGreen("导出称号卡").setExecuteCommand("/mplt get_card " + args[1]).build());
} }
view.add(Line.create().append("---------------------")); view.add(Line.create().append("---------------------"));
view.add(operate); view.add(operate);