Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: tnt explosion doesn't count a kill #381

Merged
merged 1 commit into from
Jun 19, 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
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down