From 00898f3ef3befb59e2e73af1372d696a31b8bb0f Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 22 Jan 2024 23:03:23 +0800 Subject: [PATCH] add tab display --- pom.xml | 2 +- .../cn/lunadeer/miniplayertitle/Events.java | 33 +++++++------------ .../cn/lunadeer/miniplayertitle/XPlayer.java | 31 ++++++++++++++++- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 4889e5a..3b3719e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer MiniPlayerTitle - 2.7.2 + 2.8.5 jar MiniPlayerTitle diff --git a/src/main/java/cn/lunadeer/miniplayertitle/Events.java b/src/main/java/cn/lunadeer/miniplayertitle/Events.java index b93c9d7..7e2ce94 100644 --- a/src/main/java/cn/lunadeer/miniplayertitle/Events.java +++ b/src/main/java/cn/lunadeer/miniplayertitle/Events.java @@ -3,6 +3,7 @@ package cn.lunadeer.miniplayertitle; import cn.lunadeer.miniplayertitle.utils.Notification; import io.papermc.paper.event.player.AsyncChatEvent; import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -11,33 +12,21 @@ public class Events implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - XPlayer player = new XPlayer(event.getPlayer()); - Commands.home_view(event.getPlayer()); + Player bukkitPlayer = event.getPlayer(); + XPlayer player = new XPlayer(bukkitPlayer); + Commands.home_view(bukkitPlayer); + player.updateName(); } @EventHandler public void onPlayerSendChat(AsyncChatEvent event) { - XPlayer xPlayer = new XPlayer(event.getPlayer()); - PlayerTitle title = xPlayer.getTitle(); Component nameComponent = event.getPlayer().displayName(); Component chatComponent = event.message(); - if (title == null) { - Component newChatComponent = Component.text() - .append(Component.text("<")) - .append(nameComponent) - .append(Component.text("> ")) - .append(chatComponent).build(); - event.setCancelled(true); - event.getPlayer().getServer().sendMessage(newChatComponent); - } else { - Component titleComponent = title.getTitle(); - Component newChatComponent = Component.text().append(titleComponent) - .append(Component.text("<")) - .append(nameComponent) - .append(Component.text("> ")) - .append(chatComponent).build(); - event.setCancelled(true); - event.getPlayer().getServer().sendMessage(newChatComponent); - } + Component newChatComponent = Component.text() + .append(nameComponent) + .append(Component.text(" ")) + .append(chatComponent).build(); + event.setCancelled(true); + event.getPlayer().getServer().sendMessage(newChatComponent); } } diff --git a/src/main/java/cn/lunadeer/miniplayertitle/XPlayer.java b/src/main/java/cn/lunadeer/miniplayertitle/XPlayer.java index 3f9d1dc..78b31dc 100644 --- a/src/main/java/cn/lunadeer/miniplayertitle/XPlayer.java +++ b/src/main/java/cn/lunadeer/miniplayertitle/XPlayer.java @@ -62,6 +62,7 @@ public class XPlayer { sql += "updated_at = CURRENT_TIMESTAMP "; sql += "WHERE uuid = '" + _player.getUniqueId() + "';"; Database.query(sql); + updateName(); if (_current_title_id == -1) { Notification.info(_player, "成功卸下称号"); return; @@ -196,7 +197,7 @@ public class XPlayer { Notification.info(_player, title.getTitle().append(Component.text(" 已购买至 " + title_bought.getExpireAtStr()))); } - public void custom(String title_str){ + public void custom(String title_str) { if (this.get_coin() < MiniPlayerTitle.config.getCustomCost()) { Notification.error(this._player, "称号币不足"); return; @@ -226,4 +227,32 @@ public class XPlayer { Notification.info(this._player, Component.text("成功创建自定义称号: ").append(title.getTitle())); Notification.info(this._player, "花费: " + MiniPlayerTitle.config.getCustomCost() + "称号币,余额: " + this.get_coin() + "称号币"); } + + public void updateName() { + PlayerTitle title = getTitle(); + if (title == null) { + Component newDisplayName = Component.text() + .append(Component.text("<")) + .append(_player.name()) + .append(Component.text("> ")).build(); + Component newListName = Component.text() + .append(_player.name()).build(); + _player.displayName(newDisplayName); + _player.playerListName(newListName); + return; + } + + Component titleComponent = title.getTitle(); + Component newDisplayName = Component.text() + .append(titleComponent) + .append(Component.text("<")) + .append(_player.name()) + .append(Component.text(">")).build(); + Component newListName = Component.text() + .append(titleComponent) + .append(Component.text(" ")) + .append(_player.name()).build(); + _player.displayName(newDisplayName); + _player.playerListName(newListName); + } }