Class O2Spell
- Direct Known Subclasses:
ABERTO,AddO2Effect,AddPotionEffect,ALIQUAM_FLOO,ALOHOMORA,AMATO_ANIMO_ANIMATO_ANIMAGUS,APARECIUM,APPARATE,ARRESTO_MOMENTUM,AVADA_KEDAVRA,AVIS,BombardaSuper,BRACKIUM_EMENDO,ChangeEntitySizeSuper,CISTERN_APERIO,ColoroSuper,CRESCERE_PROTEGAT,DEFODIO,DELETRIUS,DEPRIMO,DIFFINDO,DISSENDIUM,Divination,ET_INTERFICIAM_ANIMAM_LIGAVERIS,EXPELLIARMUS,FIANTO_DURI,FIENDFYRE,FINESTRA,FINITE_INCANTATEM,FRANGE_LIGNEA,GaleatiSuper,HARMONIA_NECTERE_PASSUS,HERBIVICUS,HORREAT_PROTEGAT,IGNOSCO,IMPERVIUS,IncendioSuper,INFORMOUS,ItemEnchant,Knockback,LACARNUM_INFLAMARI,LEGILIMENS,LIGATIS_COR,LUMOS_CAERULEUM,LUMOS_DUO,LUMOS_MAXIMA,LUMOS_SOLEM,MetelojinxSuper,MULTICORFORS,OBLIVIATE,OPPUGNO,PACK,PARTIS_TEMPORUS,PETRIFICUS_TOTALUS,POINT_ME,PRIOR_INCANTATO,PROPHETEIA,Pyrotechnia,REDUCTO,RemoveO2Effect,RemovePotionEffect,REPARIFARGE,REPARIFORS,REPARO,SCUTO_CONTERAM,SILENCIO,SKURGE,SparksBase,StationarySpell,TransfigurationBase,VENTO_FOLIO,WINGARDIUM_LEVIOSA
Provides core spell functionality including projectile movement, collision detection, validation,
cooldowns, and basic lifecycle management. All spells cast by players extend this class and must
implement spell-specific behavior in doCheckEffect().
Spell Lifecycle:
- Spell is instantiated with player and wand information
initSpell()is called to perform player-based initialization (uses, skills, etc.)- Each game tick,
checkEffect()is called to update spell state - Projectile moves via
move()until it hits a block or reaches max distance - Spell-specific effects are applied via
doCheckEffect() - Spell is terminated via
kill(), which callsrevert()for cleanup
Spell Validation: Spells are validated against Ollivanders2 configuration settings and WorldGuard permissions. Invalid spells are automatically terminated.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected O2MagicBranchThe branch of magic this spell isstatic final StringThe message for cooldown spell failuresstatic final doubleThe default radius for spells when checking for conditions(optional) Flavor text for this spell in spellbooks, etc.static final StringThe message for an isAllowed failureorg.bukkit.LocationThe location of the spell projectilestatic final intThe max distance a spell projectile can travelstatic final intMax spell lifetime in gameticks, 10 minutes, this is used to ensure a code bug doesn't create never-ending spells.booleanDoes this spell do a spell projectile or not.org.bukkit.entity.PlayerThe player who cast this spell.doubleRepresents which wand the user was holding.static final intA spell is considered mastered at level 100The type this spell is.protected StringThe description text for this spell in spell books.doubleThe modifier for this spell based on usage.org.bukkit.util.VectorThe vector of the projectile. -
Constructor Summary
ConstructorsConstructorDescriptionO2Spell(@NotNull Ollivanders2 plugin, @NotNull org.bukkit.entity.Player player, @NotNull Double rightWand) ConstructorO2Spell(Ollivanders2 plugin) Default constructor should only be used for fake instances of the spell such as when initializing the book text. -
Method Summary
Modifier and TypeMethodDescriptionvoidMain game tick update called every server tick while the spell is active.protected abstract voidSpell-specific effects and behavior executed each game tick.@NotNull List<org.bukkit.entity.Entity> getCloseEntities(double radius) Gets entities within a radius of current spell projectile location, excluding the casterlongGet the spell's casting cooldownGet the failure message string@Nullable StringGet the spell's book flavor text@NotNull MagicLevelgetLevel()Get the level of this spell.intGet the number of ticks this spell has been alive for@NotNull O2MagicBranchGet the spell's branch of magic@NotNull StringgetName()Get the name of the spell@NotNull List<org.bukkit.entity.Damageable> getNearbyDamageableEntities(double radius) Get all damageable entities within the radius of projectile, including the caster if within the radius@NotNull List<org.bukkit.entity.Item> getNearbyItems(double radius) Get all item entities within the radius of the projectile@NotNull List<org.bukkit.entity.LivingEntity> getNearbyLivingEntities(double radius) Get all living entities within the radius of projectile, including the caster if within the radius@NotNull List<org.bukkit.entity.Player> getNearbyPlayers(double radius) Get all players within the radius of projectile, including the caster if within the radius.Get the success message string@Nullable org.bukkit.block.BlockGet the target block for the spell.@NotNull StringgetText()Get the spell's book textList<com.sk89q.worldguard.protection.flags.StateFlag> Get the world guard flags for this spell.booleanWhether this spell has hit a targetbooleanCheck if the projectile has exceeded its maximum travel distance.booleanisKilled()Whether this spell has been killedbooleanCheck to see if this spell is allowed per Ollivanders2 config and WorldGuard.voidkill()Terminates this spell, stopping projectile movement and performing cleanup.voidmove()Advances the spell projectile one block in its direction of travel.protected voidrevert()Reverts any temporary changes made to the world by this spell.voidSend the player the failure message, if it exists, for this spellvoidSend the player the success message, if it exists, for this spellprotected voidCalculate and set theusesModifierbased on spell experience, wand type, and player level.
-
Field Details
-
maxSpellLifetime
public static final int maxSpellLifetimeMax spell lifetime in gameticks, 10 minutes, this is used to ensure a code bug doesn't create never-ending spells. Permanent and semi-permanent spells need to use stationary spells or effects.- See Also:
-
maxProjectileDistance
public static final int maxProjectileDistanceThe max distance a spell projectile can travel- See Also:
-
spellMasteryLevel
public static final int spellMasteryLevelA spell is considered mastered at level 100- See Also:
-
isAllowedFailureMessage
The message for an isAllowed failure- See Also:
-
cooldownMessage
The message for cooldown spell failures- See Also:
-
player
public org.bukkit.entity.Player playerThe player who cast this spell. -
spellType
The type this spell is. -
location
public org.bukkit.Location locationThe location of the spell projectile -
usesModifier
public double usesModifierThe modifier for this spell based on usage. This is for spells that change behavior based on the caster's experience. -
vector
public org.bukkit.util.Vector vectorThe vector of the projectile. -
rightWand
public double rightWandRepresents which wand the user was holding. See Ollivanders2Common.wandCheck() -
noProjectile
public boolean noProjectileDoes this spell do a spell projectile or not. Generally spells will send a projectile but any spell that targets the caster, such as apparate, should not. -
branch
The branch of magic this spell is -
flavorText
(optional) Flavor text for this spell in spellbooks, etc. -
text
The description text for this spell in spell books. Required or spell cannot be written in a book. -
defaultRadius
public static final double defaultRadiusThe default radius for spells when checking for conditions- See Also:
-
-
Constructor Details
-
O2Spell
Default constructor should only be used for fake instances of the spell such as when initializing the book text.- Parameters:
plugin- a callback to the plugin
-
O2Spell
public O2Spell(@NotNull @NotNull Ollivanders2 plugin, @NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Double rightWand) Constructor- Parameters:
plugin- a callback to the O2 pluginplayer- the player casting the spellrightWand- wand check for the player
-
-
Method Details
-
getWorldGuardFlags
Get the world guard flags for this spell.- Returns:
- a copy of the world guard flags
-
checkEffect
public void checkEffect()Main game tick update called every server tick while the spell is active.Handles core spell lifecycle logic:
- Validates spell is allowed at current location; kills if not
- Increments spell lifetime and kills if exceeding max lifetime
- Moves projectile via
move()if projectile hasn't hit a target - Executes spell-specific effects via
doCheckEffect()
Subclasses typically override
doCheckEffect()instead of this method. Only override this method if you need to customize the spell's entire tick behavior. -
move
public void move()Advances the spell projectile one block in its direction of travel.Called each game tick while the spell is active and hasn't hit a target. Performs the following:
- Checks if spell has been killed or already hit target; exits early if so
- Checks if projectile has exceeded max travel distance; kills spell if so
- Updates projectile location and fires
OllivandersSpellProjectileMoveEvent - Validates spell is still allowed at new location per config and WorldGuard
- Plays movement visual effect at new location
- Checks if projectile hit a solid block; stops projectile and validates block target if so
The projectile travels in the direction specified by
vectorand can travel up tomaxProjectileDistanceblocks before being automatically terminated. -
isAtMaxDistance
public boolean isAtMaxDistance()Check if the projectile has exceeded its maximum travel distance.- Returns:
- true if projectile distance exceeds max distance, false otherwise
-
isSpellAllowed
public boolean isSpellAllowed()Check to see if this spell is allowed per Ollivanders2 config and WorldGuard.- Returns:
- true if the spell can exist here, false otherwise
-
getCloseEntities
Gets entities within a radius of current spell projectile location, excluding the caster- Parameters:
radius- radius within which to get entities- Returns:
- a list of entities within the radius of the projectile
-
getNearbyItems
Get all item entities within the radius of the projectile- Parameters:
radius- radius within which to get entities- Returns:
- a list of item entities within the radius of projectile
-
getNearbyLivingEntities
@NotNull public @NotNull List<org.bukkit.entity.LivingEntity> getNearbyLivingEntities(double radius) Get all living entities within the radius of projectile, including the caster if within the radius- Parameters:
radius- radius within which to get entities- Returns:
- a list of living entities within one block of projectile
-
getNearbyPlayers
Get all players within the radius of projectile, including the caster if within the radius.- Parameters:
radius- radius within which to get entities- Returns:
- a list of players within the specified radius of projectile
-
getNearbyDamageableEntities
@NotNull public @NotNull List<org.bukkit.entity.Damageable> getNearbyDamageableEntities(double radius) Get all damageable entities within the radius of projectile, including the caster if within the radius- Parameters:
radius- the radius to check- Returns:
- a list of damageable entities within the radius
-
setUsesModifier
protected void setUsesModifier()Calculate and set theusesModifierbased on spell experience, wand type, and player level.The modifier accounts for:
- Spell usage count (or max level if enabled)
- Wand correctness (halved if wrong wand, doubled if elder wand)
- HIGHER_SKILL effect (doubles modifier)
- Player year/level compared to spell level (if years enabled)
-
getTargetBlock
@Nullable public @Nullable org.bukkit.block.Block getTargetBlock()Get the target block for the spell.- Returns:
- the target block
-
doCheckEffect
protected abstract void doCheckEffect()Spell-specific effects and behavior executed each game tick.Called each tick from
checkEffect()after validation and movement logic. Subclasses must override this method to implement the spell's unique effects such as damage, block changes, particle effects, or other gameplay mechanics. -
kill
public void kill()Terminates this spell, stopping projectile movement and performing cleanup.Stops the projectile via
stopProjectile(), performs spell-specific cleanup viarevert(), and marks the spell as killed so it will no longer be processed. -
revert
protected void revert()Reverts any temporary changes made to the world by this spell.Called when the spell is terminated via
kill(). Subclasses should override this method to undo any temporary block changes, entity modifications, or other side effects. The default implementation does nothing. -
isKilled
public boolean isKilled()Whether this spell has been killed- Returns:
- true if the spell has been terminated, false otherwise
-
hasHitTarget
public boolean hasHitTarget()Whether this spell has hit a target- Returns:
- true if the spell has hit a target, false otherwise
-
getCoolDown
public long getCoolDown()Get the spell's casting cooldown- Returns:
- the cool-down time for this spell in ticks
-
getText
Get the spell's book text- Returns:
- the book text for this spell
-
getFlavorText
Get the spell's book flavor text- Returns:
- the flavor text for this spell
-
getMagicBranch
Get the spell's branch of magic- Returns:
- the branch of magic for this spell
-
getName
Get the name of the spell- Returns:
- the name of the spell
-
getLifeTicks
public int getLifeTicks()Get the number of ticks this spell has been alive for- Returns:
- the lifeticks for this spell
-
getLevel
Get the level of this spell. This is primarily for use with counter-spells- Returns:
- the level of the spell
-
sendSuccessMessage
public void sendSuccessMessage()Send the player the success message, if it exists, for this spell -
getSuccessMessage
Get the success message string- Returns:
- the success message string if set, or an empty string if not set
-
sendFailureMessage
public void sendFailureMessage()Send the player the failure message, if it exists, for this spell -
getFailureMessage
Get the failure message string- Returns:
- the failure message string if set, or an empty string if not set
-