Issues with detecting player damage!

Discussion in 'Plugin Development' started by AstramG, Apr 24, 2014.

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

    AstramG

    Greetings! Recently I've been trying to code a KitPvP plugin, and I'm working on preventing kill steals. I have all of the calculations and algorithms set up to prevent kill stealing but there is still one issue that remains. The event.getDamage() method returns the damage done by the weapon and not to the hurt player. Currently Bukkit doesn't contain any method for calculating the damage done to players with respect to armor, enchants, and potion effects. And I'm in need of a method exactly like that. I've thought of work arounds such as getting the players health before the EntityHurtEntity event is even called, and then subtracting that by the players health in the method, to get the amount of damage done, but that is terribly inefficient and could probably somehow be viable for manipulation and could be inconsistent. Does anybody have a suggestion on how they would approach getting the EXACT damage done to the player, with respect to armor, potions, and enchants?
     
  2. Offline

    AstramG

    Here is a quick summary of the issue for those who say tl;dr:

    EntityDamageByEntity event's getDamage() method only returns the damage that the weapons does without the victims armor, enchants, and potion damage reduction. I'm trying to get the finalized damage.
     
  3. Offline

    xTigerRebornx

    AstramG I don't believe there is a method in the BukkitAPI itself, I'd look into some NMS or manual calculations of it.
     
  4. Offline

    AstramG

    It'd be inefficient to do the manual calculations :p
     
  5. Offline

    xTigerRebornx

    AstramG How so? There is no method in the Bukkit API, it'd only be inefficient if you made it inefficient
     
  6. Offline

    BillyGalbreath

    Sounds like something a PR could fix. ^_^
     
  7. Offline

    AstramG

    If you'd be willing to that, that'd be great. But I know you're giving away your plugins, so the chances of you doing any more Bukkit Development is slim, am I right?
     
  8. Offline

    BillyGalbreath

    Correct. But someone can. Maybe even you. ;)
     
  9. Offline

    AstramG

    Seriously, a manual calculation for every item that increases defense is detrimental. There are tons of armor pieces and combinations of enchants. It'd be a good 50-150 lines of code for just getting the defense of the player, which definitely shouldn't be the case. Now using NMS could work by intercepting the damage packet sent the client possibly? Not too sure if that's the right method of approaching it or not, I'd need to look into it.

    I probably could but I don't know a good approach for detecting it. I'm too inexperienced with NMS to be able to accomplish something like this. :p

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

    xTigerRebornx

    AstramG 50-150 lines of code? Not really, more like a few methods. One for doing armor calculations (with Protection addon), one for Potion effects, and possibly some ease-of-access methods for doing the enchants and equations. It sounds like a lot, but its really not. And when I say NMS, I mean going into the net.minecraft.server classes and getting the fields that store the armor value (which is why you'd still need to do calculations even using NMS)
     
  11. Offline

    AstramG

    I know what NMS is. But, if you could show me which classes in the code to search for, I could use reflection to get the armor values. Just not too sure where to look for this stuff.
     
  12. The problem is, that you can't know the final damage, due to randomization with enchantments , potion effects, and possibly other. Minecraft/Bukkit would have to provide a method that returns an interval [min, max], but it seems they have other things to do than adding proper damage-API :). Probably one could talk Bukkit devs into adding a utility to determine if a certain potion effect reduces damage for an attack type or if a certain piece of armor affects the damage type, which would already help a lot for the calculations. Not sure Bukkit actually reflects the Minecraft damage sources well enough to do this...

    Assume a much simpler case for just explosion damage... have you done it before?

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

    xTigerRebornx

  14. Offline

    xTigerRebornx

    asofold I did not count lines, as it didn't really matter. And it wouldn't be for damage types, it'd be for defense types, unless the damage event also forgets about the weapon's enchants that are used.
     
  15. Fall damage applies differently, fire, blast, ... one would have to match those vs. the armor types and also the defensive enchantment types - you will need to check both offensive
    and defensive specs.

    Edit: If they want to reliably detect "this event kills" they need to at least consider fire. Also they have to do the nodamageticks calculations.

    Edit2: Also poison, instant damage and the like, though i am not sure if those affect armor.
     
Thread Status:
Not open for further replies.

Share This Page