Skip to content

Commit b3c2b35

Browse files
vLuckyyyRollczi
andauthored
GH-915 Fix death message handling, add {CAUSE} placeholder and update PL/EN configurations (#915)
* Fix death message handling, add {CAUSE} placeholder and update PL/EN configurations * Simplify if statement * Fix. * Fix. --------- Co-authored-by: Rollczi <[email protected]>
1 parent 870ba42 commit b3c2b35

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/deathmessage/DeathMessageController.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import com.eternalcode.core.notice.NoticeService;
88
import com.eternalcode.multification.notice.Notice;
99
import java.util.List;
10+
import org.bukkit.entity.Entity;
1011
import org.bukkit.entity.Player;
1112
import org.bukkit.event.EventHandler;
1213
import org.bukkit.event.Listener;
14+
import org.bukkit.event.entity.EntityDamageByEntityEvent;
1315
import org.bukkit.event.entity.EntityDamageEvent;
1416
import org.bukkit.event.entity.PlayerDeathEvent;
1517

@@ -30,43 +32,41 @@ class DeathMessageController implements Listener {
3032
@EventHandler
3133
void onPlayerDeath(PlayerDeathEvent event) {
3234
Player player = event.getEntity();
33-
3435
event.setDeathMessage(null);
3536

36-
if (player.getKiller() != null) {
37+
EntityDamageEvent damageCause = player.getLastDamageCause();
38+
39+
if (damageCause instanceof EntityDamageByEntityEvent causeByEntity && causeByEntity.getDamager() instanceof Player killer) {
3740
this.noticeService.create()
3841
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().deathMessage()))
3942
.placeholder("{PLAYER}", player.getName())
40-
.placeholder("{KILLER}", player.getKiller().getName())
43+
.placeholder("{KILLER}", killer.getName())
4144
.onlinePlayers()
4245
.send();
43-
4446
return;
4547
}
4648

47-
EntityDamageEvent lastDamageCause = player.getLastDamageCause();
48-
49-
if (lastDamageCause == null) {
49+
if (damageCause != null) {
50+
EntityDamageEvent.DamageCause cause = damageCause.getCause();
5051
this.noticeService.create()
51-
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().unknownDeathCause()))
52+
.noticeOptional(translation -> {
53+
List<Notice> notifications = translation.event().deathMessageByDamageCause().get(cause);
54+
55+
if (notifications == null) {
56+
return RandomElementUtil.randomElement(translation.event().unknownDeathCause());
57+
}
58+
59+
return RandomElementUtil.randomElement(notifications);
60+
})
5261
.placeholder("{PLAYER}", player.getName())
62+
.placeholder("{CAUSE}", cause.name())
5363
.onlinePlayers()
5464
.send();
5565
return;
5666
}
5767

5868
this.noticeService.create()
59-
.noticeOptional(translation -> {
60-
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
61-
62-
List<Notice> notifications = translation.event().deathMessageByDamageCause().get(cause);
63-
64-
if (notifications == null) {
65-
return RandomElementUtil.randomElement(translation.event().unknownDeathCause());
66-
}
67-
68-
return RandomElementUtil.randomElement(notifications);
69-
})
69+
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().unknownDeathCause()))
7070
.placeholder("{PLAYER}", player.getName())
7171
.onlinePlayers()
7272
.send();

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,34 @@ public static class ENChatSection implements ChatSection {
286286
@Getter
287287
@Contextual
288288
public static class ENEventSection implements EventSection {
289-
@Description("# {PLAYER} - Killed player, {KILLER} - Killer")
289+
@Description({
290+
"# {PLAYER} - Killed player",
291+
"# {KILLER} - Killer (only for PvP deaths)"
292+
})
290293
public List<Notice> deathMessage = List.of(
291294
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>died!"),
292295
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>was killed by <dark_red>{KILLER}!")
293296
);
294297

295298
@Description({
296-
"# EternalCore will pick a random message for the list below, every time the player do a various action.",
297-
"# If the {KILLER} not be found, the message will be picked from list if contains cause.",
299+
"# Messages shown when a player dies from specific damage causes",
300+
"# {PLAYER} - Killed player",
301+
"# {CAUSE} - Death cause (e.g., FALL, VOID)",
298302
"# List of DamageCauses: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html"
299303
})
300304
public Map<EntityDamageEvent.DamageCause, List<Notice>> deathMessageByDamageCause = Map.of(
301-
EntityDamageEvent.DamageCause.VOID, Collections.singletonList(Notice.chat("<white>☠ <dark_red>{PLAYER} <red>fell into the void!")),
305+
EntityDamageEvent.DamageCause.VOID, Collections.singletonList(
306+
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>fell into the void!")
307+
),
302308
EntityDamageEvent.DamageCause.FALL, Arrays.asList(
303309
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>fell from a high place!"),
304310
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>fell off a deadly cliff!")
305311
)
306312
);
307313

314+
@Description("# {PLAYER} - Player who died from an unknown cause")
308315
public List<Notice> unknownDeathCause = List.of(
309-
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>died!")
316+
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>died under mysterious circumstances!")
310317
);
311318

312319
@Description({"", "# {PLAYER} - Player who joined"})

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,27 +291,34 @@ public static class PLChatSection implements ChatSection {
291291
@Getter
292292
@Contextual
293293
public static class PLEventSection implements EventSection {
294-
@Description("# {PLAYER} - Gracz który został uśmiercony, {KILLER} - Gracz który zabił gracza")
294+
@Description({
295+
"# {PLAYER} - Gracz, który zginął",
296+
"# {KILLER} - Gracz, który zabił (tylko w przypadku PvP)"
297+
})
295298
public List<Notice> deathMessage = List.of(
296299
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął przez {KILLER}!"),
297-
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął tragicznie podczas cieżkiej walki!")
300+
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął tragicznie podczas ciężkiej walki!")
298301
);
299302

300303
@Description({
301-
"# EternalCore będzie losować losową wiadomość z poniższej listy, za każdym razem gdy gracz zginie.",
302-
"# Jeżeli {KILLER} nie będzie uwzględniony to wiadomość zostanie pobrana z tej listy.",
303-
"# Lista powodów zgonu: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html"
304+
"# Wiadomości wyświetlane gdy gracz ginie od konkretnego typu obrażeń",
305+
"# {PLAYER} - Gracz, który zginął",
306+
"# {CAUSE} - Przyczyna śmierci (np. UPADEK, VOID)",
307+
"# List of DamageCauses: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html"
304308
})
305309
public Map<EntityDamageEvent.DamageCause, List<Notice>> deathMessageByDamageCause = Map.of(
306-
EntityDamageEvent.DamageCause.VOID, Collections.singletonList(Notice.chat("<white>☠ <dark_red>{PLAYER} <red>wypadł z naszego świata!")),
310+
EntityDamageEvent.DamageCause.VOID, Collections.singletonList(
311+
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>wypadł w otchłań!")
312+
),
307313
EntityDamageEvent.DamageCause.FALL, Arrays.asList(
308314
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>spadł z wysokości!"),
309315
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>spadł z zabójczego klifu!")
310316
)
311317
);
312318

319+
@Description("# {PLAYER} - Gracz, który zginął z nieznanej przyczyny")
313320
public List<Notice> unknownDeathCause = List.of(
314-
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>został zabity przez niezidentyfikowany obiekt bojowy!")
321+
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>został zabity przez niezidentyfikowany obiekt!")
315322
);
316323

317324
@Description({

0 commit comments

Comments
 (0)