EntityDamageEvent event.getDamage() ignores damage deducted by armor

Discussion in 'Plugin Development' started by redside100, Jan 23, 2015.

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

    redside100

    Hey guys, I'm currently making a 1v1 plugin that checks if a player's health subtracted by the event damage is less than 1, and if it is, it teleports them to their saved location. The thing is, event.getDamage() returns the total damage of the event, disregarding the damage absorbed by the armor. So, for example, if you were hit by a diamond sword, and you were wearing diamond armor, it would return as 8 (4 hearts), instead of 1 (half a heart). Here's my code:

    Code:
                    if ((p.getHealth() - e.getDamage()) < 1){
                        e.setCancelled(true);
                        if (p.equals(lore.ingame.get(0))){
                            Player p2 = lore.ingame.get(1);
                            lore.getServer().broadcastMessage(lore.prefix + "§a" + p2.getName() + " beat " + p.getName() + " in a 1v1!");
                            lore.removePlayer(p2);
                            lore.removePlayer(p);
                            lore.ingame.clear();
                            lore.started = false;
                        }
                        if (p.equals(lore.ingame.get(1))){
                            Player p2 = lore.ingame.get(0);
                            lore.getServer().broadcastMessage(lore.prefix + "§a" + p2.getName() + " beat " + p.getName() + " in a 1v1!");
                            lore.removePlayer(p2);
                            lore.removePlayer(p);
                            lore.ingame.clear();
                            lore.started = false;
                        }
                    }
     
  2. Offline

    mythbusterma

  3. Offline

    redside100

    Problem is, I implemented some abilities too. For example, there is this ability called "Berserk", and when you use it you do 25% more damage for 3 seconds.
     
  4. Offline

    mythbusterma

    @redside100

    Seems to me like that would be the easiest one to check, as it is internal to your plugin.
     
  5. Offline

    WinX64

    Depending on the version of the API you're using, you can do this with EntityDamageEvent#getFinalDamage. It will return the damage the entity will receive after all the damage reduction has been applied(Armor, Effects, etc).
     
    Last edited: Jan 24, 2015
    redside100 and Konato_K like this.
  6. Offline

    redside100

    Yeah, I read that on the java docs, but I can't find a place to download it. Could you send me a link?

    // EDIT: This may help, it says this on the javadocs:
    1.7.9-R0.2-63-gcb87f4e
     
  7. Offline

    WinX64

  8. Offline

    redside100

    Most of these downloads lead to a 404...
     
  9. Just click on the big one "1.7.9"
     
  10. Offline

    redside100

    I downloaded the jar from the big "1.7.9" button, but it still didn't include the getFinalDamage() method.
     
  11. Offline

    Konato_K

  12. Offline

    1Rogue

    You need to compile bukkit yourself from the github repository.
     
  13. Nop .
     
  14. Offline

    1Rogue

    It was a commit in July 2014 that was removed and is only present in the code on github. So that is what you need to do, despite whatever you tell yourself.
     
Thread Status:
Not open for further replies.

Share This Page