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

Fix friend death message broadcasts #1125

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
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
22 changes: 22 additions & 0 deletions core/src/main/java/tc/oc/pgm/death/DeathMessageMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
}