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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected doubleThe maximum distance we can move thingsprotected intThe maximum number of targetsprotected doubleThe minimum distance we can move thingsprotected intThis reduces how strong the knockback is.protected org.bukkit.util.VectorThe velocity this knockback will add to the targetFields inherited from class net.pottercraft.ollivanders2.spell.O2Spell
branch, cooldownMessage, defaultRadius, flavorText, isAllowedFailureMessage, location, maxProjectileDistance, maxSpellLifetime, noProjectile, player, rightWand, spellMasteryLevel, spellType, text, usesModifier, vector -
Constructor Summary
ConstructorsConstructorDescriptionKnockback(@NotNull Ollivanders2 plugin, @NotNull org.bukkit.entity.Player player, @NotNull Double rightWand) Constructor.Knockback(Ollivanders2 plugin) Default constructor for use in generating spell text. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidFinds an entity at the projectile location and applies velocity to it.doubleGet the maximum distance for knockback.doubleGet the maximum radiusintGet the maximum number of targetsdoubleGet the minimum distance for knockback.intGet the strength reducer for this spell.org.bukkit.util.VectorGet the velocity for this spell.booleanisPull()Check if this spell pulls toward the caster.booleanCheck if this spell can target multiple entities.booleanCheck if this spell targets the caster.booleanCheck if this spell applies vertical knockback.Methods inherited from class net.pottercraft.ollivanders2.spell.O2Spell
checkEffect, getCloseEntities, getCoolDown, getFailureMessage, getFlavorText, getLevel, getLifeTicks, getMagicBranch, getName, getNearbyDamageableEntities, getNearbyItems, getNearbyLivingEntities, getNearbyPlayers, getSuccessMessage, getTargetBlock, getText, getWorldGuardFlags, hasHitTarget, isAtMaxDistance, isKilled, isSpellAllowed, kill, move, revert, sendFailureMessage, sendSuccessMessage, setUsesModifier
-
Field Details
-
strengthReducer
protected int strengthReducerThis reduces how strong the knockback is. 1 is max strength, any number higher than one will reduce the strength. -
minDistance
protected double minDistanceThe minimum distance we can move things -
maxDistance
protected double maxDistanceThe maximum distance we can move things -
maxTargets
protected int maxTargetsThe maximum number of targets -
velocity
protected org.bukkit.util.Vector velocityThe velocity this knockback will add to the target
-
-
Constructor Details
-
Knockback
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 pluginplayer- the player who cast this spellrightWand- 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:
doCheckEffectin classO2Spell
-
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
-