Class PlayerAttackEntityEvent

java.lang.Object
fr.fidorial.event.player.PlayerAttackEntityEvent
All Implemented Interfaces:
Cancellable, Event, PlayerEvent

public final class PlayerAttackEntityEvent extends Object implements PlayerEvent, Cancellable
Fired when a player swings at an entity, before any damage is applied.
Since:
0.1.0
  • Constructor Details

    • PlayerAttackEntityEvent

      public PlayerAttackEntityEvent(Player player, Entity target, float damage, double knockback, float attackStrength, boolean critical, boolean sweeping)
      Creates an event.
      Parameters:
      player - the attacking player
      target - the entity being hit
      damage - the damage about to be dealt, in half-hearts
      knockback - the horizontal knockback strength about to be applied
      attackStrength - the attack cooldown charge of the swing
      critical - whether the swing is a critical hit
      sweeping - whether the swing also hits the entities around the target
      Since:
      0.1.0
  • Method Details

    • player

      public Player player()
      Description copied from interface: PlayerEvent
      Returns the player involved in this event.
      Specified by:
      player in interface PlayerEvent
      Returns:
      the player involved in this event
    • target

      public Entity target()
      Returns the entity being hit.
      Returns:
      the entity being hit
      Since:
      0.1.0
    • damage

      public float damage()
      Returns:
      the damage about to be dealt, in half-hearts, critical already applied
    • setDamage

      public void setDamage(float damage)
      Parameters:
      damage - the damage to deal instead; <= 0 makes the hit harmless
    • knockback

      public double knockback()
      Returns:
      the horizontal knockback strength about to be applied
    • setKnockback

      public void setKnockback(double knockback)
      Parameters:
      knockback - the knockback strength to apply instead; 0 disables it
    • attackStrength

      public float attackStrength()
      Returns:
      the attack cooldown charge of this swing, between 0.2 and 1
    • isCritical

      public boolean isCritical()
      Returns:
      true when this swing landed as a critical hit
    • isSweeping

      public boolean isSweeping()
      Returns:
      true when this swing also hits the entities around the target
    • setSweeping

      public void setSweeping(boolean sweeping)
      Parameters:
      sweeping - false to keep the hit on the primary target only
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Cancellable
      Returns true if the action this event describes will not happen.
      Specified by:
      isCancelled in interface Cancellable
      Returns:
      true if the action this event describes will not happen
    • setCancelled

      public void setCancelled(boolean cancelled)
      Description copied from interface: Cancellable
      Prevents or re-allows the action this event describes.
      Specified by:
      setCancelled in interface Cancellable
      Parameters:
      cancelled - true to prevent it