Discussion in 'Programming' started by Azarus, Jan 18, 2020.

  1. Im just trying to figure out how to compare an to an entity. For example, I'm doing a EntityShootBowEvent naming it "event" then i do event.getEntity(), it gives me that specific entity. Now how would I go about putting it in an if statement. if(event.getEntity().equals(Skeleton)){//code here}. but that doesnt work. Any ideas?
  2. You can use the instanceof operator:

    Code (Java):

    if (event.getEntity() instanceof Skeleton) {}
    • Like Like x 1
    • Winner Winner x 1
  3. Thanks, is that the best approach to do it in most cases?
  4. Yep. `instanceof` is generally frowned upon (often it's used when it shouldn't), but here (or in all cases where you need to check for the type of entity in an event) it's exactly what you need.
  5. Thank you much.