Class Knockback

java.lang.Object
net.pottercraft.ollivanders2.spell.O2Spell
net.pottercraft.ollivanders2.spell.Knockback
Direct Known Subclasses:
ACCIO, ALARTE_ASCENDARE, ARANIA_EXUMAI, ASCENDIO, CARPE_RETRACTUM, DEPULSO, FLIPENDO

public abstract class Knockback extends O2Spell
Abstract base class for spells with knockback effects (push/pull, vertical/horizontal).

Provides common functionality for calculating and applying velocity to entities. Subclasses must implement canTarget(Entity) to determine valid targets. The spell finds the nearest valid entity at the projectile location, calculates the appropriate velocity based on distance and drag factors, and applies it to the target.

  • Field Details

    • strengthReducer

      protected int strengthReducer
      This reduces how strong the knockback is. 1 is max strength, any number higher than one will reduce the strength.
    • minDistance

      protected double minDistance
      The minimum distance we can move things
    • maxDistance

      protected double maxDistance
      The maximum distance we can move things
    • maxTargets

      protected int maxTargets
      The maximum number of targets
    • velocity

      protected org.bukkit.util.Vector velocity
      The velocity this knockback will add to the target
  • Constructor Details

    • Knockback

      public Knockback(Ollivanders2 plugin)
      Default constructor for use in generating spell text. Do not use to cast the spell.
      Parameters:
      plugin - the Ollivanders2 plugin
    • Knockback

      public Knockback(@NotNull @NotNull Ollivanders2 plugin, @NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Double rightWand)
      Constructor.
      Parameters:
      plugin - a callback to the MC plugin
      player - the player who cast this spell
      rightWand - which wand the player was using
  • Method Details

    • doCheckEffect

      protected void doCheckEffect()
      Finds an entity at the projectile location and applies velocity to it.

      Searches for a valid target entity near the projectile, calculates the appropriate velocity based on the caster's skill level, and applies the velocity to the target. For vertical spells targeting entities underwater, the distance is capped to prevent launching them out of water at unrealistic speeds.

      Specified by:
      doCheckEffect in class O2Spell
    • getVelocity

      public org.bukkit.util.Vector getVelocity()
      Get the velocity for this spell.
      Returns:
      the velocity this spell will add to the target entity
    • isPull

      public boolean isPull()
      Check if this spell pulls toward the caster.
      Returns:
      true if the spell pulls, false if it pushes
    • isVertical

      public boolean isVertical()
      Check if this spell applies vertical knockback.
      Returns:
      true if the knockback is vertical (Y-axis), false if horizontal
    • isTargetsSelf

      public boolean isTargetsSelf()
      Check if this spell targets the caster.
      Returns:
      true if the spell affects the caster, false if it targets other entities
    • isTargetsMultiple

      public boolean isTargetsMultiple()
      Check if this spell can target multiple entities.
      Returns:
      true if it can target multiple, false otherwise
    • getStrengthReducer

      public int getStrengthReducer()
      Get the strength reducer for this spell.
      Returns:
      the strength reducer value (higher values reduce knockback strength)
    • getMinDistance

      public double getMinDistance()
      Get the minimum distance for knockback.
      Returns:
      the minimum distance
    • getMaxDistance

      public double getMaxDistance()
      Get the maximum distance for knockback.
      Returns:
      the maximum distance
    • getMaxRadius

      public double getMaxRadius()
      Get the maximum radius
      Returns:
      the max radius
    • getMaxTargets

      public int getMaxTargets()
      Get the maximum number of targets
      Returns:
      the max targets