Getting player health in EntityDamageEvent

Discussion in 'Plugin Development' started by SaxSalute, Apr 27, 2014.

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

    SaxSalute

    Part of my plugin involves teleporting a player somewhere when they die instead of using the respawn screen. However, I have a problem. For some reason my calculation of health after damage, damagedPlayer.getHealth() - event.getDamage(), seems to be giving me the amount of health the player would have disregarding armor. At the very least the calculation seems to give a strangely low number. How can I go about fixing this issue?
     
  2. Offline

    MrKeals

    Can you post the code ?
     
  3. Offline

    SaxSalute

    Code:
    if (event.getEntity() == null)
                return;
            else if (!(event.getEntity() instanceof Player))
                return;
     
            Player damagedPlayer = (Player) event.getEntity();
           
            System.out.println("Health Before: " + (damagedPlayer.getHealth()));
            System.out.println("Health After: " + (damagedPlayer.getHealth() - event.getDamage()));
           
            //If the player is in the arena system but not in game
            if (plugin.getArenaManager().getPlayerStatus(damagedPlayer) != null && !plugin.getArenaManager().getPlayerStatus(damagedPlayer).equals(LobbyStatus.IN_GAME))
            {
                event.setCancelled(true);
                return;
            }
           
            Game game = plugin.getArenaManager().getGameManager().getGameByParticipant(damagedPlayer);
           
            //Return if the player is not in a game
            if (game == null)
                return;
           
            //Cancel damage if player is dead
            if (game.getGameManager().getPlayerStatus(damagedPlayer).equals(InGameStatus.DEAD))
                event.setCancelled(true);
           
            if (damagedPlayer.getHealth() - event.getDamage() > 0)
                return;
           
            event.setCancelled(true);
            killPlayer(damagedPlayer, game);
     
  4. Offline

    MrKeals

    Try this :
    Health Before: (damagedPlayer.getHealth() + event.getDamage());
    Health After : damagedPlayer.getHealth();
     
Thread Status:
Not open for further replies.

Share This Page