Solved Find who killed a player, and who they killed

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

  1. Offline

    FireBreath14

    My BukkitDev Profile
    My Plugins (6)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    Code (Text):
    1. package *name censored lol*;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.entity.ProjectileHitEvent;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10.  
    11. public class OnHit implements Listener{
    12.     public void onhit(ProjectileHitEvent event){
    13.         Player killer = (Player)event.getEntity().getShooter(); //get who shot the snowball
    14.         Player victim = //HELP HERE :)
    15.     }
    16. }
    17.  
    thanks!
     
  2. Offline

    david_rosales

    My BukkitDev Profile
    My Plugins (8)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    event.getEntity()
     
  3. Offline

    Eballer48

    My BukkitDev Profile
    My Plugins (0)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Wrong event silly! :p

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


    Code:java
    1.  
    2. @EventHandler
    3. public void onHit(EntityDeathEvent event) {
    4. if (!(event.getEntity() instanceof Player)) {
    5. return;
    6. }
    7.  
    8. Player player = (Player) event.getEntity();
    9.  
    10. if (!(player.getKiller() instanceof Snowball)) {
    11. return;
    12. }
    13.  
    14. Snowball Snowball = (Snowball) player.getKiller();
    15.  
    16. if (!(Snowball.getShooter() instanceof Player)) {
    17. return;
    18. }
    19.  
    20. Player shooter = (Player) Snowball.getShooter();
    21.  
    22. }
    23.  



    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. Offline

    vemacs

    My BukkitDev Profile
    My Plugins (5)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Why don't you have an @EventHandler?
     
  5. Offline

    david_rosales

    My BukkitDev Profile
    My Plugins (8)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    event.getEntity()
     
  6. Offline

    david_rosales

    My BukkitDev Profile
    My Plugins (8)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    So it would be
    Player victim = (Player) event.getEntity();
     
  7. Offline

    mastermustard

    My BukkitDev Profile
    My Plugins (2)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code (Text):
    1.     @EventHandler
    2.     public void onAttackEvent(EntityDamageEvent event){
    3.         Entity entity = event.getEntity();
    4.    
    5.       if(entity instanceof Player){
    6.         if(event instanceof EntityDamageByEntityEvent){
    7.         if(event instanceof ProjectileHitEvent){
    8.           //damaged entity
    9.             EntityDamageByEntityEvent cod = (EntityDamageByEntityEvent)event;
    10.             if(cod.getDamager() instanceof Player){
    11.                 Player damager = (Player)cod.getDamager();
    12.                 //damager
     
  8. Offline

    Eballer48

    My BukkitDev Profile
    My Plugins (0)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    FireBreath14

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


    Edit:

    Re-updated, didn't realize you said Snowballs, my code was for Arrows.
     
  9. Offline

    FireBreath14

    My BukkitDev Profile
    My Plugins (6)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Eballer48 ok so ur code, its for a entitydeathevent? got it. and it looks helpful so thanks xD!
     
  10. Offline

    FireBreath14

    My BukkitDev Profile
    My Plugins (6)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    yess all the required vars. thanks soooo much Eballer48!
     
  11. Offline

    Eballer48

    My BukkitDev Profile
    My Plugins (0)
    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    No problem haha! Ever need any help just tag me!
     

Share This Page