Skip to content

Instantly share code, notes, and snippets.

@stephan-gh
Last active December 21, 2015 04:48
Show Gist options
  • Save stephan-gh/6252245 to your computer and use it in GitHub Desktop.
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.
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