Detect player hit without PvP

Discussion in 'Plugin Development' started by matejdro, Feb 21, 2011.

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


    How can i detect, when player hits another player without PvP (so no damage involved)?
  2. Offline


    I don't have a development environment available right now, but isn't EntityDamageEvent what you're after in this case?

    I believe you'll implement it the same way you implement blocklisteners and player listeners, except that it is entities.

    so i guess you'll create a new class that implements EntityListener and override onEntityDamageByEntity(EntityDamageByEntityEvent event)

    and then in the main plugin class you would do:
    pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Low, this);
    with the appropriate priority, ofc ;-)
  3. Offline


    AFAIK EntityDamage event triggers only when there is damage done to the player. But i need something that works when PvP is off (no damage between players)
  4. Offline


    gah, disregard my post, i looked at old stuff, newest craftbukkit doesn't even have ENTITY_DAMAGEDBY_ENTITY :p

    I'll do some checking myself when I get the opportunity, right now i've gotta run :(
    --- merged: Feb 21, 2011 1:28 PM ---
    alright, as far as i see, ENTITY_DAMAGED events are still getting passed around with pvp=false, so implementing EntityListener and overriding onEntityDamage(EntityDamageEvent event) should do the trick
  5. Offline


    you could do something like:
    if(onEntityDamage == event.getPlayer){
    player.sendMessage('Hey there he hit me wahwahh)
    I am not exactly sure if this is correct, this is just how i though of it
  6. Offline


    I think he got it working, since there were no more replies ;)

    But to recap, afaik, all you would need to do is to create a class that extends EntityListener and then override the onEntityDamage method, then you would check the event itself for what kind of damage it is, what pops to mind is this:

        public void onEntityDamage(EntityDamageEvent event) {
            if(event.getCause().equals(DamageCause.ENTITY_ATTACK)) {
    these events gets passed around even though pvp is turned off (i think the only difference is that the event itself is set to cancelled at the event source)
  7. Offline


    I did not get chance to test that yet. I know that onEntityDamage triggers when you hit somebody, just i did not know that it triggers even when PvP is turned off and no damage is done.

    Thanks for all the replies, i will test as soon as i can and report.
Thread Status:
Not open for further replies.

Share This Page