Solved How to check what entity type in a EntityDamageByEntityEvent?

Discussion in 'Plugin Development' started by Nonam82, Aug 7, 2016.

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

    Nonam82

    Basically the title. I want to detect damage to an entity if it is a sheep. I tried using something like this:
    Code:
    if (event.getEntity().equals(EntityType.SHEEP) ){
       Bukkit.getLogger().info("Sheep has been hit!");
    }
    else{
       Bukkit.getLogger().info("A non-sheep has been hit!");
    }
    When I tested this ingame, it printed that a non-sheep had been hit when I hit a sheep. What is the correct way to test for a certain type of entity?
     
  2. Offline

    slingshot2008

    Try

    event.getEntity() instanceof Sheep
     
  3. Offline

    SuperSniper

    Would work

    You could also do this though:
    if(e.getEntity().getType() == EntityType.SHEEP) {
     
    slingshot2008 likes this.
Thread Status:
Not open for further replies.

Share This Page