[SOLVED] Best way to perform action when player dies AND stop the player from dieing?

Discussion in 'Plugin Development' started by thekris1234, Jul 22, 2011.

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



    I'm making a PvP Arena plugin for my server and I want the players to be teleported back to where they were before the match and retrieve all their items when one player kills the other.

    What's the best way of detecting the player is dead or is about to die (such as on the next hit) and save them from death so I can perform the above actions?
  2. Offline


    You could use EntityDamageByEntityEvent, but how you would know a person were to die on the next hit is beyond me, because different weapon hit for different amounts of damage.
    I would just use EntityDeathEvent and then setCancelled(true)
  3. Offline


    EntityDeathEvent cannot be cancelled, so you'll have to use EntityDamageByEntityEvent. Just check if the incoming damage is greater than the amount of health the target has, and if so, teleport and cancel the event.
  4. Offline


    ok. I've changed it to entitydamagebyentity. Do I need to change the listener in onEnable? At the moment it is:

    pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);

    but it doesn't seem to be working.
  5. Offline


    You need to check if its damage by entity, then cast accordingly...so
    2. public void onEntityDamage(EntityDamageEvent event){
    3. if(event instanceof EntityDamageByEntityEvent){
    4. EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event;
    5. if(nEvent.getDamage() >= nEvent.getEntity().getHealth()){
    6. //do stuff
    7. }
    8. }
  6. Offline


    Brilliant. Thank you very much.
Thread Status:
Not open for further replies.

Share This Page