Skip to content

Commit bb130ae

Browse files
CitralFlogemini-code-assist[bot]Rollczi
authored
GH-373 Add opponent placeholder in combat notification (#373)
* Add opponent placeholder in combat notification Signed-off-by: Michał Wojtas <wojtas.michal90@gmail.com> * Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Signed-off-by: Michał Wojtas <wojtas.michal90@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Norbert Dejlich <ndejlich5@gmail.com>
1 parent 2c5b007 commit bb130ae

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/MessagesSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class MessagesSettings extends OkaeriConfig {
1616
" ",
1717
"# Configure the combat log notification displayed to players.",
1818
"# You can use the {TIME} variable to display the remaining combat time.",
19+
"# Placeholder {OPPONENT} will be replaced with player name or 'unknownPlayerPlaceholder' variable",
1920
" ",
2021
})
2122
public Notice combatNotification = Notice.builder()
@@ -27,6 +28,12 @@ public class MessagesSettings extends OkaeriConfig {
2728
})
2829
public boolean withoutMillis = true;
2930

31+
@Comment({
32+
" ",
33+
"# When player is not known this text will be used as {OPPONENT} in 'combatNotification'"
34+
})
35+
public String unknownPlayerPlaceholder = "Unknown";
36+
3037
@Comment({
3138
"# Message displayed when a player lacks permission to execute a command.",
3239
"# The {PERMISSION} placeholder is replaced with the required permission."

eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.eternalcode.combat.fight.event.CauseOfUnTag;
55
import com.eternalcode.combat.notification.NoticeService;
66
import com.eternalcode.combat.util.DurationUtil;
7+
import java.util.Optional;
78
import org.bukkit.Server;
89
import org.bukkit.entity.Player;
910

@@ -17,7 +18,7 @@ public class FightTask implements Runnable {
1718
private final FightManager fightManager;
1819
private final NoticeService noticeService;
1920

20-
public FightTask(Server server, PluginConfig config, FightManager fightManager, NoticeService noticeService) {
21+
public FightTask(Server server, PluginConfig config, FightManager fightManager, NoticeService noticeService) {
2122
this.server = server;
2223
this.config = config;
2324
this.fightManager = fightManager;
@@ -42,10 +43,17 @@ public void run() {
4243

4344
Duration remaining = fightTag.getRemainingDuration();
4445

46+
String opponent = Optional.ofNullable(fightTag.getTagger())
47+
.filter(uuid -> !uuid.equals(playerUniqueId))
48+
.map(this.server::getPlayer)
49+
.map(Player::getName)
50+
.orElse(this.config.messagesSettings.unknownPlayerPlaceholder);
51+
4552
this.noticeService.create()
4653
.player(player.getUniqueId())
4754
.notice(this.config.messagesSettings.combatNotification)
4855
.placeholder("{TIME}", DurationUtil.format(remaining, this.config.messagesSettings.withoutMillis))
56+
.placeholder("{OPPONENT}", opponent)
4957
.send();
5058

5159
}

0 commit comments

Comments
 (0)