add tab display
Some checks failed
Java CI-CD with Maven / build (push) Failing after 37m9s

This commit is contained in:
zhangyuheng 2024-01-22 23:03:23 +08:00
parent 79979c9825
commit 00898f3ef3
3 changed files with 42 additions and 24 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId>
<version>2.7.2</version>
<version>2.8.5</version>
<packaging>jar</packaging>
<name>MiniPlayerTitle</name>

View File

@ -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);
}
}

View File

@ -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);
}
}