Last active
December 21, 2015 04:48
-
-
Save stephan-gh/6252245 to your computer and use it in GitHub Desktop.
Get the real player damager behind an entity, for example if an entity was damaged by an arrow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Player getPlayerDamager(Entity damager) { | |
if (damager instanceof Player) return (Player) damager; | |
if (damager instanceof Projectile) { | |
Projectile projectile = (Projectile) damager; | |
Object shooter = projectile.getShooter(); // Doesn't really matter but will also make it work with pre 1.7 | |
if (shooter != null && (shooter instanceof Player)) return (Player) shooter; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment