Simple Question - Can Player Hit A Pig

Discussion in 'Plugin Development' started by Joey Clover, Mar 20, 2011.

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

    Joey Clover

    How can I check that a player hits a certain mob?
    Need reply ASAP.
    Regards,
    Joey Clover
     
  2. Offline

    Crash

    onEntityDamaged
     
  3. Offline

    Joey Clover

    Figured ;)
    BUT how do I write to files? I know how to set properties and read them ans stuff but how do I do it like others:

    Code:
    blahblah=29
    blahblah2=lol
    ###############
    HOW DO I DO THIS
    ###############
    blahblah3=23
    How would I put those lines in the middle?
    I know props.setProperty and stuff but I can't seem to write the middle lines.

    AND onEntityDamage offers no way to find the 'CreatureType' that was attacked.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  4. Offline

    Crash

    Using instanceof to get the type of damage event and also instanceof for the entity to check which type

    if(event instanceof EntityDamageByEntityEvent){

    EntityDamageByEntityEvent e = (EntityDamageByEntityEvent)event;
    if(e.getDamagee() instanceof Pig){

    //stuff

    }

    }
     
  5. Offline

    Joey Clover

    There is no damagee, only damager and damage :/
     
  6. Offline

    Mixcoatl

    Try this:
    Code:
    if (event.getCause() == DamageCause.ENTITY_ATTACK && event.getEntity() instanceof Pig) {
      // Do pig stuff.
    }
     
  7. Offline

    Joey Clover

    Much easier now, thanks. One last thing. How to get the name of the PLAYER dealing the damage?

    help pl0x

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  8. Offline

    Mixcoatl

    Use:
    Code:
    if (event.getCause() == DamageCause.ENTITY_ATTACK && event.getEntity() instanceof Pig) {
      final EntityDamageByEntityEvent realEvent =
        (EntityDamageByEntityEvent) event;
      // Do pig stuff.
      if (realEvent.getDamager() instanceof Player) {
        final String damagerName =
          ((Player) realEvent.getDamager()).getName();
        // Do pig stuff using player's name.
      }
    }
     
Thread Status:
Not open for further replies.

Share This Page