Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-915 Fix death message handling, add {CAUSE} placeholder and update PL/EN configurations #915

Merged
merged 4 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,42 +32,38 @@ class DeathMessageController implements Listener {
@EventHandler
void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();

event.setDeathMessage(null);

if (player.getKiller() != null) {
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().deathMessage()))
.placeholder("{PLAYER}", player.getName())
.placeholder("{KILLER}", player.getKiller().getName())
.onlinePlayers()
.send();
EntityDamageEvent damageCause = player.getLastDamageCause();

return;
if (damageCause instanceof EntityDamageByEntityEvent) {
Entity damaged = ((EntityDamageByEntityEvent) damageCause).getDamager();
if (damaged instanceof Player killer) {
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().deathMessage()))
.placeholder("{PLAYER}", player.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()))
.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);
List<Notice> messages = translation.event().unknownDeathCause();
return RandomElementUtil.randomElement(messages);
})
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,27 +281,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 @@ -286,27 +286,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