EntityDamageByEntityEvent

Discussion in 'Plugin Development' started by Codisimus, Mar 26, 2011.

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

    Codisimus

    i cant get onEntityDamage (EntityDamageByEntityEvent event) to work... does it not exist anymore or sumthing?
     
  2. Offline

    Intelli

    Like this?

    Code:
    
    @Override
        public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof EntityDamageByEntityEvent) {
    
    EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
                Entity entity = sub.getEntity();
            	Entity entity2 = sub.getDamager();
    
    if (entity2 instanceof Player && entity instanceof Player) {
    
    Player player = (Player) entity;
    player.sendMessage("You were attacked by another player.");
    
    }
    }
    }
    
     
  3. Offline

    Codisimus

    thank you! this was the only part i couldnt figure out how to do
     
  4. Offline

    Drakia

    If you always include the @Override one line above your event function, then Eclipse will tell you if you have the function definition wrong :)
     
  5. Offline

    Codisimus

    well i use netbeans but i knew sumthing was wrong bc it didnt tell me i needed to add @Override
     
  6. Offline

    Valrix

    How would you check if the entity being hit is a mob instead of a player? I tried entity instanceof Monster and that doesn't work.

    EDIT: Never mind, found out I was doing the main event wrong. instanceof Monster works perfect.
     
  7. Offline

    Crash

    if(!(entity instanceof Player))

    EDIT : Actually I think there are other things like an arrow that could pass this so..
    Monster should be working though..
     
Thread Status:
Not open for further replies.

Share This Page