Compare commits

..

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

7 changed files with 71 additions and 12 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%"> <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.7.1</version> <version>4.6.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.7-SNAPSHOT</version> <version>1.3.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>

View File

@ -34,7 +34,7 @@ public class Expansion extends PlaceholderExpansion {
if (t == null) { if (t == null) {
return ""; return "";
} }
return t.getTitleColoredBukkit(); return ChatColor.translateAlternateColorCodes('&', 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 MiniPlayerTitle.instance.getDescription().getVersion(); return plugin.getPluginMeta().getVersion();
} }
} }

View File

@ -4,6 +4,7 @@ import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO; import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import cn.lunadeer.miniplayertitle.tuis.MyTitles;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -64,7 +65,6 @@ public class TitleCard implements Listener {
} }
use(player, item); use(player, item);
player.getInventory().removeItem(item); player.getInventory().removeItem(item);
event.setCancelled(true);
} }
private static ItemStack create(@NotNull TitleShopDTO saleInfo) { private static ItemStack create(@NotNull TitleShopDTO saleInfo) {

View File

@ -5,11 +5,13 @@ import cn.lunadeer.miniplayertitle.MiniPlayerTitle;
import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerInfoDTO;
import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO; import cn.lunadeer.miniplayertitle.dtos.PlayerTitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleDTO; import cn.lunadeer.miniplayertitle.dtos.TitleDTO;
import cn.lunadeer.miniplayertitle.dtos.TitleShopDTO;
import cn.lunadeer.miniplayertitle.tuis.AllTitles; import cn.lunadeer.miniplayertitle.tuis.AllTitles;
import cn.lunadeer.miniplayertitle.tuis.MyTitles; import cn.lunadeer.miniplayertitle.tuis.MyTitles;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName; import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;

View File

@ -1,16 +1,21 @@
package cn.lunadeer.miniplayertitle.dtos; 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.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;
@ -75,8 +80,32 @@ public class TitleDTO {
} }
public TextComponent getTitleColored() { public TextComponent getTitleColored() {
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix(); TextComponent prefix = Component.text(MiniPlayerTitle.config.getPrefix(), new Color("#ffffff").getStyle());
return ColorParser.getComponentType(with_pre_suf); 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 * @return String
*/ */
public String getTitleColoredBukkit() { public String getTitleColoredBukkit() {
String with_pre_suf = "&#ffffff" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&#ffffff" + MiniPlayerTitle.config.getSuffix(); String title = "&f" + MiniPlayerTitle.config.getPrefix() + getTitleRaw() + "&f" + MiniPlayerTitle.config.getSuffix();
return ColorParser.getBukkitType(with_pre_suf); 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() { 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() { public Integer getId() {

View File

@ -1,6 +1,8 @@
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;