Solved PlayerDeathEvent, Cant get player or killer?

Discussion in 'Plugin Development' started by Ultracrepadarian, Sep 6, 2015.

Thread Status:
Not open for further replies.
  1. Hello! I'd like some help with my plugin, Basically, the event is going to check if they're dead, (which they are) then check if they're in an arena, then do something to the killer (probably give him/her points/credits). Anyway, I've registered my events in onEnable:

    getServer().getPluginManager().registerEvents(this, this);

    And here is my event:

    @EventHandler
    public void killEvent(PlayerDeathEvent e)
    {
    //Bla bla bla
    }

    But my problem is this: Whenever I try to do "Player player = e.getPlayer();", It says "The method getPlayer() is undefined for the type PlayerDeathEvent". I also tried to do "e." and then scroll down and try to find it, But it doesn't have getPlayer() or getKiller(). Help please :)

    P.S Thanks in advance! :)
     
  2. Offline

    Oxyorum

  3. Offline

    Konato_K

    @Ultracrepadarian How to get the player is answered by Oxyorum, also, to get the killer you need to call #getKiller() in your player, this is a method of Entity and always returns a Player object, it may also be null.
     
  4. Offline

    SuperSniper

    @Ultracrepadarian
    PlayerDeathEvent is the same as EntityDeathEvent in many ways.
    I recommend using EntityDeathEvent rather than PlayerDeathEvent though.
    Both events have the same methods for getting the killed & killer.

    PlayerDeathEvent:
    Code:
    public void onDeath(PlayerDeathEvent e) {
        if(e.getEntity() instanceof Player && e.getEntity().getKiller() instanceof Player) {
       Player died = (Player)e.getEntity();
       Player killed = (Player)e.getEntity().getKiller();
        // do stuff
    
    EntityDeathEvent:
    Code:
    public void onDeath(EntityDeathEvent e) {
        if(e.getEntity() instanceof Player && e.getEntity().getKiller() instanceof Player) {
       Player died = (Player)e.getEntity();
       Player killed = (Player)e.getEntity().getKiller();
        // do stuff
    
     
  5. So basically, I would use EntityDeathEvent, check if it's a player, if it is, then specify that player as "player", then use player.getKiller()? Correct?

    @SuperSniper
    @Konato_K
    @Oxyorum
     
  6. Offline

    oceantheskatr

  7. Thanks everyone for the help :)

    SOLVED! Right now I'm on my phone, so ill mark it as solved later...
     
    Last edited: Sep 6, 2015
  8. Offline

    caderape

    @Ultracrepadarian You can use playerDeathevent if you just wanna check when a player is killed. This event is called when a player dies, so you don't have to check if the entity is a player
     
  9. But I want to get the killer, So that wouldnt work...
     
  10. Offline

    Oxyorum

  11. Ah sorry, I saw his post on TapaTalk, so it didn't show the code snippets. Thanks anyway, but its solved :)
     
Thread Status:
Not open for further replies.

Share This Page