diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/Events.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/Events.java index ef3519039..8253ebbfc 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/Events.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/Events.java @@ -1,33 +1,38 @@ package net.sacredlabyrinth.phaed.simpleclans.listeners; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; -public class Events { +public final class Events { - private Events() {} + private Events() { + // Can't instantiate this class + } @Nullable @Contract("null -> null") public static Player getAttacker(@Nullable EntityDamageEvent parentEvent) { - if (parentEvent instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) parentEvent; + if (parentEvent instanceof EntityDamageByEntityEvent sub) { + Entity damager = sub.getDamager(); - if (sub.getDamager() instanceof Player) { - return (Player) sub.getDamager(); + if (damager instanceof Player attacker) { + return attacker; } - if (sub.getDamager() instanceof Projectile) { - Projectile projectile = (Projectile) sub.getDamager(); + if (damager instanceof Projectile projectile && projectile.getShooter() instanceof Player attacker) { + return attacker; + } - if (projectile.getShooter() instanceof Player) { - return (Player) projectile.getShooter(); - } + if (damager instanceof TNTPrimed tnt && tnt.getSource() instanceof Player attacker) { + return attacker; } + } return null; }