Solved Find who killed a player, and who they killed

Discussion in 'Plugin Development' started by FireBreath14, 23, 2013.

Thread Status:
Not open for further replies.
  1. As the title says, I want to find who shot who with a snowball, and who they killed. Heres what i have so far. I have the killer, i just don't know how to find the victim

    package *name censored lol*;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.EventHandler;
    import org.bukkit.ChatColor;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    public class OnHit implements Listener{
        public void onhit(ProjectileHitEvent event){
            Player killer = (Player)event.getEntity().getShooter(); //get who shot the snowball
            Player victim = //HELP HERE :)
  2. event.getEntity()
  3. Wrong event silly! :p

    If you want to know when the player is killed you use the EntityDeathEvent().

    2. @EventHandler
    3. public void onHit(EntityDeathEvent event) {
    4. if (!(event.getEntity() instanceof Player)) {
    5. return;
    6. }
    8. Player player = (Player) event.getEntity();
    10. if (!(player.getKiller() instanceof Snowball)) {
    11. return;
    12. }
    14. Snowball Snowball = (Snowball) player.getKiller();
    16. if (!(Snowball.getShooter() instanceof Player)) {
    17. return;
    18. }
    20. Player shooter = (Player) Snowball.getShooter();
    22. }

    Where player is your victim and shooter is your killer. Code is pretty self explanatory, if you're confused on anything let me know and I'll explain it to you the best I can!
    FireBreath14 likes this.
  4. Why don't you have an @EventHandler?
  5. event.getEntity()

    So it would be
    Player victim = (Player) event.getEntity();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: 31, 2016
  6. Code:
        public void onAttackEvent(EntityDamageEvent event){
            Entity entity = event.getEntity();
          if(entity instanceof Player){
            if(event instanceof EntityDamageByEntityEvent){
            if(event instanceof ProjectileHitEvent){
              //damaged entity
                EntityDamageByEntityEvent cod = (EntityDamageByEntityEvent)event;
                if(cod.getDamager() instanceof Player){
                    Player damager = (Player)cod.getDamager();
  7. FireBreath14

    Updated my original post, it's the correct one haha. I'm a little high so sorry pasted the wrong one.


    Re-updated, didn't realize you said Snowballs, my code was for Arrows.
  8. Eballer48 ok so ur code, its for a entitydeathevent? got it. and it looks helpful so thanks xD!

    yess all the required vars. thanks soooo much Eballer48!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: 31, 2016
  9. No problem haha! Ever need any help just tag me!
Thread Status:
Not open for further replies.

Share This Page