Solved Cancel Death via damage events

Discussion in 'Plugin Development' started by JeremyPark, Jun 2, 2014.

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

    JeremyPark

    Hi, I am having an issue with canceling the death event. I know it isn't cancellable, so I guess the way to do it is to make sure that the player doesn't technically die, but still be able to tell if they would have. The way to do this is obviously through damage events, such as in my case EntityDamageByEntityEvent. I have set it so that if a zombie kills you, you are removed from the minigame. The issue I have is that the Damage event seems to run twice, even though, the damage is only sent once. The first time that it is run, it works fine, and gets the current player's health, and current event damage. The second time, it runs as if the zombie had damaged the player in the same tick, so the next damage would be run, making the player get kicked out of the arena too early.

    Here is my code.
    Code:java
    1. public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
    2. Player player = (Player) event.getEntity();
    3. event.setDamage(10.0D);
    4. System.out.println("Player health" + ((Damageable) player).getHealth());
    5. System.out.println("Event Damage" + (((Damageable) player).getHealth() - event.getDamage()));
    6. if(((((Damageable) player).getHealth()) - event.getDamage() <= -0.5)){
    7. ArenaManager.getManager().removePlayer(player);
    8.  
    9. player.setHealth(20D);
    10.  
    11. }
    12. }


    Any help would be awesome :)
     
  2. Offline

    Arkel

    Try adding in an
    Code:java
    1. if(player.getNoDamageTicks() < (player.getMaxNoDamageTicks() /2 )) {
    2. return;
    3. }
     
  3. Offline

    teej107

    What do you mean first time run and second time run? Like getting damaged or getting removed from the minigame? You could use a PlayerDeathEvent and set their health back to 20 in it. That'll make them respawn instantly.
     
    bobthefish likes this.
  4. Offline

    JeremyPark

    Thanks, that was a great idea, and works perfectly. :) By the way, I love your signature. :)
     
Thread Status:
Not open for further replies.

Share This Page