领地提示消息新增特殊占位符 #26 #19

- `{OWNER}`:会被自动替换为领地主人的名字;
- `{DOM}`:会被自动替换为领地名称;
This commit is contained in:
ZhangYuheng 2024-09-24 16:56:20 +08:00
parent 5cc0750ee9
commit c132f52f99
4 changed files with 29 additions and 5 deletions

View File

@ -7,7 +7,7 @@ plugins {
}
group = "cn.lunadeer"
version = "2.10.0-beta"
version = "2.10.1-beta"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))

View File

@ -232,10 +232,18 @@ public class Cache implements DominionAPI {
return last_dominion;
}
if (last_dom_id != -1) {
MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), last_dominion.getLeaveMessage());
MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(),
last_dominion.getLeaveMessage()
.replace("{DOM}", last_dominion.getName())
.replace("{OWNER}", getPlayerName(last_dominion.getOwner()))
);
}
if (current_dom_id != -1) {
MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), current_dominion.getJoinMessage());
MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(),
current_dominion.getJoinMessage()
.replace("{DOM}", current_dominion.getName())
.replace("{OWNER}", getPlayerName(current_dominion.getOwner()))
);
}
lightOrNot(player, current_dominion); // 发光检查
@ -373,6 +381,16 @@ public class Cache implements DominionAPI {
return id_dominions.get(id);
}
public String getPlayerName(UUID uuid) {
if (!player_name_cache.containsKey(uuid)) {
PlayerDTO playerDTO = PlayerDTO.select(uuid);
if (playerDTO != null) {
player_name_cache.put(uuid, playerDTO.getLastKnownName());
}
}
return player_name_cache.getOrDefault(uuid, "Unknown");
}
public int getPlayerDominionCount(UUID player_uuid) {
int count = 0;
for (DominionDTO dominion : id_dominions.values()) {
@ -439,6 +457,7 @@ public class Cache implements DominionAPI {
private static final long UPDATE_INTERVAL = 1000 * 4;
private boolean recheckPlayerState = false; // 是否需要重新检查玩家状态发光飞行
public final Map<UUID, LocalDateTime> NextTimeAllowTeleport = new java.util.HashMap<>();
private final Map<UUID, String> player_name_cache = new HashMap<>();
private Map<UUID, List<ResMigration.ResidenceNode>> residence_data = null;

View File

@ -9,8 +9,8 @@ Database:
Language: zh-cn
AutoCreateRadius: 10
DefaultJoinMessage: '&3Welcome to %dominion_current_dominion%!'
DefaultLeaveMessage: '&3Leaving %dominion_current_dominion%...'
DefaultJoinMessage: '&3{OWNER}: Welcome to {DOM}!'
DefaultLeaveMessage: '&3{OWNER}: Leaving {DOM}...'
MessageDisplay:
NoPermission: ACTION_BAR

View File

@ -16,6 +16,11 @@
/dominion set_leave_msg <提示语> [领地名称]
```
## 特殊占位符
- `{OWNER}`:会被自动替换为领地主人的名字;
- `{DOM}`:会被自动替换为领地名称;
## 提示
- 提示语支持 PlaceholderAPI 占位符,例如 `%player%`