1.6.4 Bukkit Player Hitting Player Event

Discussion in 'Plugin Development' started by jigga_jones, Apr 18, 2014.

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

    jigga_jones

    Hey there i was wondering what the hook was for when a player hits another player ?
     
  2. Offline

    Xenira

    Garris0n likes this.
  3. Offline

    Europia79

    jigga_jones
    i'm not 100% sure, but I would try one of these

    http://jd.bukkit.org/dev/apidocs/org/bukkit/event/player/PlayerInteractEntityEvent.html
    http://jd.bukkit.org/dev/apidocs/org/bukkit/event/entity/EntityDamageByEntityEvent.html

    Code:java
    1. @EventHandler (priority=EventPriority.NORMAL)
    2. public void thisNameCanBeAnything(EntityDamageByEntityEvent e) {
    3. e.
    4. }


    Then, for which ever event you use, import the correct package: Ex:
    import org.bukkit.event.entity.EntityDamageByEntityEvent;

    Me personally, i would do "e." and use the IDE code completion to see what methods Bukkit has given access to.

    If you use EntityDamageByEntityEvent, then you might have to check if both entities are players.

    Anyways, my source is here
    http://jd.bukkit.org/dev/apidocs/

    Just press Control+F, type in event, and look for one that might be suitable for your situation/scenario.

    Hopefully this helps. Good luck!

    EDIT: whoops, Xenira answered while i was typing.
     
  4. Offline

    jigga_jones

    thank you :)
     
  5. Offline

    jigga_jones

    still cant get it to work is there something wrong with this code ?[​IMG]
     
  6. Offline

    Garris0n

    Yes, that's not how you make event handlers. Why does it have an entity parameter?
     
  7. Offline

    jigga_jones

    how would this work then lol ?
     
  8. Offline

    Th3Br1x

    You can call the "getEntity()" method from "event". Then you have the instance of the Entity which just got damaged.

    Edit: And there is a "getDamager()" method too. Guess what you get from that method :p
     
  9. Offline

    jigga_jones

    just a question what would be the basic code structure for when a player hits another player ?

    is there anything anyone can help me with here ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  10. Offline

    eezjzbzbzb

    You are lucky I have the same code in my plugin :p

    Code:java
    1. @EventHandler
    2. public void onPlayerDamageByEntity(EntityDamageByEntityEvent event){
    3. if(event.getEntityType() == EntityType.PLAYER){ //If the EntityType of the victim is the same as EntityType.PLAYER
    4. if(event.getDamager().getType() == EntityType.PLAYER){ //If the EntityType of the damager is the same as EntityType.PLAYER
    5. Player damager = (Player)event.getDamager(); //Dont forget to cast Player
    6. Player victim = (Player)event.getEntity(); //Here also cast Player
    7. // . . .
    8. }
    9. }
    10. }
     
    Europia79 likes this.
Thread Status:
Not open for further replies.

Share This Page