Skip to content

Commit

Permalink
GH-915 Fix death message handling, add {CAUSE} placeholder and update…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
vLuckyyy and Rollczi authored Feb 15, 2025
1 parent 870ba42 commit b3c2b35
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.multification.notice.Notice;
import java.util.List;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;

Expand All @@ -30,43 +32,41 @@ class DeathMessageController implements Listener {
@EventHandler
void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();

event.setDeathMessage(null);

if (player.getKiller() != null) {
EntityDamageEvent damageCause = player.getLastDamageCause();

if (damageCause instanceof EntityDamageByEntityEvent causeByEntity && causeByEntity.getDamager() instanceof Player killer) {
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().deathMessage()))
.placeholder("{PLAYER}", player.getName())
.placeholder("{KILLER}", player.getKiller().getName())
.placeholder("{KILLER}", killer.getName())
.onlinePlayers()
.send();

return;
}

EntityDamageEvent lastDamageCause = player.getLastDamageCause();

if (lastDamageCause == null) {
if (damageCause != null) {
EntityDamageEvent.DamageCause cause = damageCause.getCause();
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().unknownDeathCause()))
.noticeOptional(translation -> {
List<Notice> notifications = translation.event().deathMessageByDamageCause().get(cause);

if (notifications == null) {
return RandomElementUtil.randomElement(translation.event().unknownDeathCause());
}

return RandomElementUtil.randomElement(notifications);
})
.placeholder("{PLAYER}", player.getName())
.placeholder("{CAUSE}", cause.name())
.onlinePlayers()
.send();
return;
}

this.noticeService.create()
.noticeOptional(translation -> {
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();

List<Notice> notifications = translation.event().deathMessageByDamageCause().get(cause);

if (notifications == null) {
return RandomElementUtil.randomElement(translation.event().unknownDeathCause());
}

return RandomElementUtil.randomElement(notifications);
})
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().unknownDeathCause()))
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,34 @@ public static class ENChatSection implements ChatSection {
@Getter
@Contextual
public static class ENEventSection implements EventSection {
@Description("# {PLAYER} - Killed player, {KILLER} - Killer")
@Description({
"# {PLAYER} - Killed player",
"# {KILLER} - Killer (only for PvP deaths)"
})
public List<Notice> deathMessage = List.of(
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>died!"),
Notice.chat("<white>☠ <dark_red>{PLAYER} <red>was killed by <dark_red>{KILLER}!")
);

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

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

@Description({"", "# {PLAYER} - Player who joined"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,34 @@ public static class PLChatSection implements ChatSection {
@Getter
@Contextual
public static class PLEventSection implements EventSection {
@Description("# {PLAYER} - Gracz który został uśmiercony, {KILLER} - Gracz który zabił gracza")
@Description({
"# {PLAYER} - Gracz, który zginął",
"# {KILLER} - Gracz, który zabił (tylko w przypadku PvP)"
})
public List<Notice> deathMessage = List.of(
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął przez {KILLER}!"),
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął tragicznie podczas cieżkiej walki!")
Notice.actionbar("<white>☠ <dark_red>{PLAYER} <red>zginął tragicznie podczas ciężkiej walki!")
);

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

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

@Description({
Expand Down

0 comments on commit b3c2b35

Please sign in to comment.