1.15.2 API Question - getEntityType() or getEntity().getType()

Discussion in 'Spigot Plugin Development' started by mind_overflow, Feb 4, 2020.

Thread Status:
Not open for further replies.
  1. Hi! I have a question as I think the API is confusing (in this particular case) and I'd like to clarify things.

    So let's take as an example an EntityDamageEvent.

    Code (Java):
    @EventHandler
        public void onEntityDamage(EntityDamageEvent event)
        {
            EntityType et1 = event.getEntityType();
            EntityType et2 = event.getEntity().getType();
        }
    As you can see, to get the EntityType of the damaged entity, I can either call event.getEntityType(); or event.getEntity().getType();.

    The question is: why?
    Why are there two methods to do exactly the same thing? Is there any performance difference between the two? When should one be used instead of the other one?

    Thanks!
     
  2. SteelPhoenix

    Moderator

    EntityDamageEvent#getEntityType() literally just calls getEntity().getType(), it's just a handy method to make life easier
     
    • Like Like x 1
  3. That's what I thought. Thanks, even though I don't really see the point :LOL: it probably takes like half a second more to write getEntity().getType() instead of getEntityType(). Still I understand that someone might find it useful.

    Thanks again!
     
Thread Status:
Not open for further replies.