Class CriticalHitEvent


public class CriticalHitEvent extends PlayerEvent
This event is fired when a player attacks an entity in Player.attack(Entity). It can be used to change the critical hit status and damage modifier

In the event the attack was not a critical hit, the event will still be fired, but it will be preemptively cancelled.

  • Field Details Link icon

    • target Link icon

      private final Entity target
    • vanillaDmgMultiplier Link icon

      private final float vanillaDmgMultiplier
    • isVanillaCritical Link icon

      private final boolean isVanillaCritical
    • dmgMultiplier Link icon

      private float dmgMultiplier
    • isCriticalHit Link icon

      private boolean isCriticalHit
  • Constructor Details Link icon

  • Method Details Link icon

    • getTarget Link icon

      public Entity getTarget()
      Returns the entity that was attacked by the player.
      Returns:
      the entity that was attacked by the player
    • getDamageMultiplier Link icon

      public float getDamageMultiplier()
      The damage multiplier is applied to the base attack's damage if the attack critically hits.

      A damage multiplier of 1.0 will not change the damage, a value of 1.5 will increase the damage by 50%, and so on.

      Parameters:
      modifier - The new damage modifier.
    • setDamageMultiplier Link icon

      public void setDamageMultiplier(float dmgMultiplier)
      Sets the damage multiplier for the critical hit. Not used if isCriticalHit() is false.

      Changing the damage modifier to zero does not guarantee that the attack does zero damage.

      Parameters:
      modifier - The new damage modifier. Must not be negative.
      See Also:
    • isCriticalHit Link icon

      public boolean isCriticalHit()
      Returns if the attack will critically hit.
      Returns:
      if the attack will critically hit
    • setCriticalHit Link icon

      public void setCriticalHit(boolean isCriticalHit)
      Changes the critical hit state.
      Parameters:
      isCriticalHit - true if the attack should critically hit
    • getVanillaMultiplier Link icon

      public float getVanillaMultiplier()
      Gets the original damage multiplier set by vanilla.

      If the event isVanillaCritical(), the damage multiplier will be 1.5, otherwise it will be 1.0

      See Also:
    • isVanillaCritical Link icon

      public boolean isVanillaCritical()
      Returns true if the attack was considered a critical hit by vanilla.
      Returns:
      true if the attack was considered a critical hit by vanilla