Class O2Spell

java.lang.Object
net.pottercraft.ollivanders2.spell.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

public abstract class O2Spell extends Object
Abstract base class for all Ollivanders2 spells.

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:

  1. Spell is instantiated with player and wand information
  2. initSpell() is called to perform player-based initialization (uses, skills, etc.)
  3. Each game tick, checkEffect() is called to update spell state
  4. Projectile moves via move() until it hits a block or reaches max distance
  5. Spell-specific effects are applied via doCheckEffect()
  6. Spell is terminated via kill(), which calls revert() for cleanup

Spell Validation: Spells are validated against Ollivanders2 configuration settings and WorldGuard permissions. Invalid spells are automatically terminated.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected O2MagicBranch
    The branch of magic this spell is
    static final String
    The message for cooldown spell failures
    static final double
    The default radius for spells when checking for conditions
    protected List<String>
    (optional) Flavor text for this spell in spellbooks, etc.
    static final String
    The message for an isAllowed failure
    org.bukkit.Location
    The location of the spell projectile
    static final int
    The max distance a spell projectile can travel
    static final int
    Max spell lifetime in gameticks, 10 minutes, this is used to ensure a code bug doesn't create never-ending spells.
    boolean
    Does this spell do a spell projectile or not.
    org.bukkit.entity.Player
    The player who cast this spell.
    double
    Represents which wand the user was holding.
    static final int
    A spell is considered mastered at level 100
    The type this spell is.
    protected String
    The description text for this spell in spell books.
    double
    The modifier for this spell based on usage.
    org.bukkit.util.Vector
    The vector of the projectile.
  • Constructor Summary

    Constructors
    Constructor
    Description
    O2Spell(@NotNull Ollivanders2 plugin, @NotNull org.bukkit.entity.Player player, @NotNull Double rightWand)
    Constructor
    Default constructor should only be used for fake instances of the spell such as when initializing the book text.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Main game tick update called every server tick while the spell is active.
    protected abstract void
    Spell-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 caster
    long
    Get the spell's casting cooldown
    Get the failure message string
    @Nullable String
    Get the spell's book flavor text
    @NotNull MagicLevel
    Get the level of this spell.
    int
    Get the number of ticks this spell has been alive for
    @NotNull O2MagicBranch
    Get the spell's branch of magic
    @NotNull String
    Get the name of the spell
    @NotNull List<org.bukkit.entity.Damageable>
    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.Block
    Get the target block for the spell.
    @NotNull String
    Get the spell's book text
    List<com.sk89q.worldguard.protection.flags.StateFlag>
    Get the world guard flags for this spell.
    boolean
    Whether this spell has hit a target
    boolean
    Check if the projectile has exceeded its maximum travel distance.
    boolean
    Whether this spell has been killed
    boolean
    Check to see if this spell is allowed per Ollivanders2 config and WorldGuard.
    void
    Terminates this spell, stopping projectile movement and performing cleanup.
    void
    Advances the spell projectile one block in its direction of travel.
    protected void
    Reverts any temporary changes made to the world by this spell.
    void
    Send the player the failure message, if it exists, for this spell
    void
    Send the player the success message, if it exists, for this spell
    protected void
    Calculate and set the usesModifier based on spell experience, wand type, and player level.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • maxSpellLifetime

      public static final int maxSpellLifetime
      Max 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 maxProjectileDistance
      The max distance a spell projectile can travel
      See Also:
    • spellMasteryLevel

      public static final int spellMasteryLevel
      A spell is considered mastered at level 100
      See Also:
    • isAllowedFailureMessage

      public static final String isAllowedFailureMessage
      The message for an isAllowed failure
      See Also:
    • cooldownMessage

      public static final String cooldownMessage
      The message for cooldown spell failures
      See Also:
    • player

      public org.bukkit.entity.Player player
      The player who cast this spell.
    • spellType

      public O2SpellType spellType
      The type this spell is.
    • location

      public org.bukkit.Location location
      The location of the spell projectile
    • usesModifier

      public double usesModifier
      The 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 vector
      The vector of the projectile.
    • rightWand

      public double rightWand
      Represents which wand the user was holding. See Ollivanders2Common.wandCheck()
    • noProjectile

      public boolean noProjectile
      Does 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

      protected O2MagicBranch branch
      The branch of magic this spell is
    • flavorText

      protected List<String> flavorText
      (optional) Flavor text for this spell in spellbooks, etc.
    • text

      protected String text
      The description text for this spell in spell books. Required or spell cannot be written in a book.
    • defaultRadius

      public static final double defaultRadius
      The default radius for spells when checking for conditions
      See Also:
  • Constructor Details

    • O2Spell

      public O2Spell(Ollivanders2 plugin)
      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 plugin
      player - the player casting the spell
      rightWand - wand check for the player
  • Method Details

    • getWorldGuardFlags

      public List<com.sk89q.worldguard.protection.flags.StateFlag> 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 vector and can travel up to maxProjectileDistance blocks 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

      @NotNull public @NotNull List<org.bukkit.entity.Entity> getCloseEntities(double radius)
      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

      @NotNull public @NotNull List<org.bukkit.entity.Item> getNearbyItems(double radius)
      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

      @NotNull public @NotNull List<org.bukkit.entity.Player> getNearbyPlayers(double radius)
      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 the usesModifier based 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 via revert(), 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

      @NotNull public @NotNull String getText()
      Get the spell's book text
      Returns:
      the book text for this spell
    • getFlavorText

      @Nullable public @Nullable String getFlavorText()
      Get the spell's book flavor text
      Returns:
      the flavor text for this spell
    • getMagicBranch

      @NotNull public @NotNull O2MagicBranch getMagicBranch()
      Get the spell's branch of magic
      Returns:
      the branch of magic for this spell
    • getName

      @NotNull public @NotNull String 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

      @NotNull public @NotNull MagicLevel 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

      public String 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

      public String getFailureMessage()
      Get the failure message string
      Returns:
      the failure message string if set, or an empty string if not set