Player to Player Damage

Discussion in 'Plugin Development' started by Satros, Jun 8, 2011.

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

    Satros

    I want to add an anti teamkill/friendly fire system to my plugin but I'm unsure how to override or use the damage event.

    I couldn't find anything to override in playerlistener for damaging another player, the closest thing I could find was the EntityDamageEvent: http://javadoc.lukegb.com/Bukkit/d0..._1_1event_1_1entity_1_1EntityDamageEvent.html

    Code:
        public void onEntityDamage(EntityDamageEvent event)
        {
            if(event.getCause() == DamageCause.ENTITY_ATTACK)
            {
    
            }
    
        }
    
    Is all I have so far. I'm unsure how to get the attacker and the victim however. There is a "getEntity ()" but that seems kind of ambiguous, because i'm not sure if it returns the attacker or the victim and furthermore I need to be able to get the display name of the attacker and victim and I'm unsure how to get those from an entity or even make sure the entity is a player and not a monster or animal.

    Essentially I need to
    -Get the attacker and victim, make sure that they are both players
    -Get attacker and victim's display names
    -(Look up in my data structure whether or not they have team kill on or off, already got that set up)
    -Cancel or allow the event depending on their flags

    Any help is appreciated
     
  2. Offline

    Trc202

  3. Offline

    Shamebot

    Cast the EntityDamageEvent to EntityDamageByEntityEvent

    Yeah that's it, thought I'd use a "==" instead of a "equals()"

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

    Satros

Thread Status:
Not open for further replies.

Share This Page