PlayerDeathEvent getEntity()

Discussion in 'Plugin Development' started by Maximvdw, Jun 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Maximvdw

    So I was checking every single Player*Event. All those have a "getPlayer()" to get the player.
    Apart from PlayerDeathEvent, it has a getEntity() method to get the Entity.

    I guess PlayerDeathEvent is the same as EntityDeathEvent, but why is that event the only event that doesn't use "getPlayer()" :p

    Just something to think about.

    - Maxim
     
  2. Offline

    Kilovice

    Maximvdw
    Code:java
    1. Player player = event.getEntity().getPlayer();
     
  3. Offline

    Necrodoom

  4. Offline

    Maximvdw

    What I mean was that every event in bukkit that has "Player" in the name has a getPlayer() method instead of the PlayerDeathEvent (what is weird because there is a seperated EntityDeathEvent).
     
  5. Offline

    MinecraftMart

    Maximvdw
    Code:java
    1. Player p = (Player) event.getEntity().getPlayer();


    Apperently this one doesnt have an direct event.getPlayer()

    We also dont know why since we arent the one that made the API

    Hope this helps
     
  6. Offline

    Necrodoom

  7. Offline

    Wolfey

    He wants to know why, not how to get the player...
     
  8. Offline

    Necrodoom

    Does no one reads the Java docs any more?
     
    Garris0n likes this.
  9. Offline

    Maximvdw

    I do :p

    So for those who don't. All "Player*Event" events have a getPlayer returning a Player. Apart from the death event having a getEntity returning a PlayerI once posted this on github but it got removed because it would break things. But this is
    1) Bad documentating
    2) Bad method naming
    getEntity

    public Player getEntity()
    Description copied from class: EntityEvent
    Returns the Entity involved in this event

    Overrides:
    getEntity in class EntityDeathEvent
    Returns:
    Entity who is involved in this event
     
  10. Offline

    Garris0n


    event.getEntity() returns a player. Calling getPlayer() on a player is completely pointless. That method is inherited from OfflinePlayer, where it has an actual use, but in Player it just returns the instance you already have. Neither of you seemed to actually read the OP, and the second one didn't even seem to notice the first's post. And both of you call getPlayer() on a player. If you can't read the OP, read the posts, and give information that isn't a terrible idea, please don't respond to threads.

    @OP The PlayerDeathEvent overrides the EntityDeathEvent. So, the getEntity() method overrides the superclass's getEntity() method. Simple as that.
     
    Konkz and AdamQpzm like this.
  11. Offline

    MinecraftMart

    Garris0n
    That, i didnt know... thaught i had it right. Well, learned something new today
     
Thread Status:
Not open for further replies.

Share This Page