((Damageable)[Entity]).damage crashing my server

Discussion in 'Plugin Development' started by John_O2, May 31, 2021.

  1. Offline


    I am trying to make a system where a player can attack another player and the damage ignores the armor.
    The code is:
    ((Damageable)playerhit).damage(event.getDamage(), thisplayer);
    and I get the entity this player and playerhit from this
    Entity thisplayer = event.getDamager();
    Entity playerhit = event.getEntity();
    When I run this code and a player hits another player it lags out the server then crashes it but when I remove the source entity from the code it works just fine but when a player kills another player it does not count as their kill.

    So this works:
  2. Online


    @John_O2 You are listening for damage and then damaging, which causes an infinite loop and crashes the server.
    davidclue and John_O2 like this.
  3. Offline


    How can I damage a player while having another player get the kill without it triggering the event again?
  4. Online


    @John_O2 You can set the player's health to their current health subtracted by the damage and then check if that is below or equal to 0. If it is, you know they will die.
  5. Offline


    @John_O2 If you use @KarimAKL idea then there will be no damage animation, why not just modify the damage in the event instead?
  6. Online


    @davidclue They want to ignore armor, which I believe the #damage method does not. Also, you can play the damage animation using EntityEffect#HURT and apply velocity for the knockback effect.
  7. Offline


    KarimAKL's solution can be used (that is setting the player's health, and of course, do the necessary checks) if you can send a PacketPlayOutAnimation that takes care of the hurting animation. (If you somehow didn't see that big table below, the hurt animation's ID is 1.)

    Another solution is that you can just invoke a literally provided method to do so.
    A notice is that this may cause chaos with snowballs and shields as md_5 mentioned and this part of the API is deprecated and can be removed.
    The API docs are here.

    Or you can see pics of logs I took for testing purposes:
    Entity was all hit by a clean diamond sword (1.8)

    So if you want to ignore ARMOR, just set the damage value 0.0 for the modifier ARMOR. Self-explanatory, right?
    Xp10d3 and KarimAKL like this.

Share This Page