From 8362d31f8c5a55dec9d892471d2eb3383978ddec Mon Sep 17 00:00:00 2001 From: applenick Date: Thu, 2 Feb 2023 12:04:12 -0800 Subject: [PATCH] Fix friend death message broadcasts Signed-off-by: applenick --- .../oc/pgm/death/DeathMessageMatchModule.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/main/java/tc/oc/pgm/death/DeathMessageMatchModule.java b/core/src/main/java/tc/oc/pgm/death/DeathMessageMatchModule.java index 29aa756a28..ec6204b7bc 100644 --- a/core/src/main/java/tc/oc/pgm/death/DeathMessageMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/death/DeathMessageMatchModule.java @@ -4,11 +4,13 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import tc.oc.pgm.api.Permissions; +import tc.oc.pgm.api.integration.Integration; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.match.MatchModule; import tc.oc.pgm.api.match.MatchScope; @@ -47,6 +49,15 @@ public void handleDeathBroadcast(MatchPlayerDeathEvent event) { viewer.sendMessage(message.decoration(TextDecoration.ITALIC, true)); } break; + case DEATH_FRIENDS: + if (event.isInvolved(viewer)) { + viewer.sendMessage(message.decoration(TextDecoration.BOLD, true)); + } else if (isFriendInvolved(viewer.getBukkit(), event)) { + viewer.sendMessage(message); + } else if (event.isTeamKill() && viewer.getBukkit().hasPermission(Permissions.STAFF)) { + viewer.sendMessage(message.decoration(TextDecoration.ITALIC, true)); + } + break; case DEATH_ALL: if (event.isInvolved(viewer) || event.isInvolved(viewer.getSpectatorTarget())) { viewer.sendMessage(message.decoration(TextDecoration.BOLD, true)); @@ -57,4 +68,15 @@ public void handleDeathBroadcast(MatchPlayerDeathEvent event) { } } } + + private boolean isFriendInvolved(Player viewer, MatchPlayerDeathEvent event) { + Player killer = + event.getKiller() != null && event.getKiller().getPlayer().isPresent() + ? event.getKiller().getPlayer().get().getBukkit() + : null; + Player victim = event.getVictim().getBukkit(); + + return (killer != null && Integration.isFriend(viewer, killer)) + || (victim != null && Integration.isFriend(viewer, victim)); + } }