From a1b7492261b7ea19d37a7fb45e3b46116cefa284 Mon Sep 17 00:00:00 2001 From: nopeless <38830903+nopeless@users.noreply.github.com> Date: Sun, 8 Jan 2023 18:20:33 -0600 Subject: [PATCH] Fix: player is no longer immune to projectiles shot by themselves --- .../nossr50/listeners/EntityListener.java | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index e94ff9c6a..d795a84eb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -362,40 +362,30 @@ public class EntityListener implements Listener { //Friendly fire checks if (defender instanceof Player defendingPlayer) { - Player attackingPlayer; - //If the attacker is a Player or a projectile belonging to a player - if(attacker instanceof Projectile || attacker instanceof Player) { - if(attacker instanceof Projectile projectile) { - if(((Projectile) attacker).getShooter() instanceof Player) { - attackingPlayer = (Player) projectile.getShooter(); + if(attacker instanceof Projectile projectile) { + if(projectile.getShooter() instanceof Player attackingPlayer && !attackingPlayer.equals(defendingPlayer)) { + //Check for party friendly fire and cancel the event + if (checkParties(event, defendingPlayer, attackingPlayer)) { + return; + } + } - //Check for party friendly fire and cancel the event - if (checkParties(event, defendingPlayer, attackingPlayer)) - { + //Deflect checks + final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(defendingPlayer); + if (mcMMOPlayer != null) { + UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); + + if (unarmedManager.canDeflect()) { + if (projectile instanceof Arrow && unarmedManager.deflectCheck()) { + event.setCancelled(true); return; } - } - - //Deflect checks - final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(defendingPlayer); - if (mcMMOPlayer != null) { - UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); - - if (unarmedManager.canDeflect()) { - if (projectile instanceof Arrow && unarmedManager.deflectCheck()) { - event.setCancelled(true); - return; - } - } - } - } else { - attackingPlayer = (Player) attacker; - //Check for party friendly fire and cancel the event - if (checkParties(event, defendingPlayer, attackingPlayer)) - return; } + } else if (attacker instanceof Player attackingPlayer){ + if (checkParties(event, defendingPlayer, attackingPlayer)) + return; } }