Class O2Spells

java.lang.Object
net.pottercraft.ollivanders2.spell.O2Spells

public class O2Spells extends Object
Central manager for all Ollivanders2 spells.

Manages spell registration, loading, and lifecycle. Maintains active spell projectiles and performs per-tick updates. Coordinates spell permission validation through a zone-based system that supports global, world-wide, WorldGuard region, and cuboid-based allow/disallow lists.

Spell Permission Hierarchy:

  1. If a global allow list is defined, only globally allowed spells can be cast
  2. Check zone-specific allow lists (WORLD, WORLD_GUARD, CUBOID) - if found, only zone-allowed spells pass
  3. Check zone-specific disallow lists - if spell is found in any zone's disallow list, deny it
  4. Check global disallow list - if spell is found, deny it
  5. If no restrictions apply, allow the spell
  • Field Details

    • wandlessSpells

      public static final List<O2SpellType> wandlessSpells
      Wandless spells
  • Constructor Details

    • O2Spells

      public O2Spells(@NotNull @NotNull Ollivanders2 plugin)
      Constructor
      Parameters:
      plugin - a callback to the MC plugin
  • Method Details

    • onEnable

      public void onEnable()
      Initializes spell data when the plugin is enabled.

      Called during plugin startup. Performs the following initialization steps:

      • Loads all available spell types from O2SpellType, skipping spells that depend on unavailable plugins (e.g., LibsDisguises spells if LibsDisguises is not installed)
      • Logs the total number of loaded spells
      • Loads spell-specific static data (e.g., Apparate locations)
      • Loads zone-based spell permission configuration from config.yml
      • Adds divination spells to the wandless spells list
    • onDisable

      public void onDisable()
      Cleanup when the plugin disables.

      Called when the Ollivanders2 plugin is being shut down. Spell projectile management (killing active projectiles) is currently handled by the main Ollivanders2.onDisable() method. When projectile management is moved to this class, cleanup will be performed here.

    • upkeep

      public void upkeep()
      Updates all active spell projectiles for one game tick.

      Called each server tick by the main scheduler. Iterates through all active spells and:

      • Calls O2Spell.checkEffect() to update each spell's state
      • Removes spells that have been killed from the active spell list

      Uses a temporary copy of the active spells list to safely remove spells during iteration.

    • getAllSpellTypes

      public static List<O2SpellType> getAllSpellTypes()
      Get all loaded spells
      Returns:
      a list of all loaded spell types
    • getSpellTypeByName

      @Nullable public @Nullable O2SpellType getSpellTypeByName(@NotNull @NotNull String name)
      Get a spell type by name.
      Parameters:
      name - the name of the spell or potion
      Returns:
      the type if found, null otherwise
    • isLoaded

      public boolean isLoaded(@NotNull @NotNull O2SpellType spellType)
      Verify this spell type is loaded. A spell may not be loaded if it depends on something such as LibsDisguises and that dependency plugin does not exist.
      Parameters:
      spellType - the spell type to check
      Returns:
      true if this spell type is loaded, false otherwise
    • loadZoneConfig

      public void loadZoneConfig()
      Load the zone config for spells
    • isSpellTypeAllowed

      public boolean isSpellTypeAllowed(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull O2SpellType spellType)
      Check if a spell is allowed based on zone config
      Parameters:
      location - the location of the spell
      spellType - the spell type to check
      Returns:
      true if spell is allowed, false otherwise
    • addSpell

      public void addSpell(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull O2Spell spell)
      Add the spell and increment cast count
      Parameters:
      player - the player who cast the spell
      spell - the spell cast
    • getActiveSpells

      @NotNull public @NotNull List<O2Spell> getActiveSpells()
      Get all the active spell projectiles
      Returns:
      a list of all active spell projectiles
    • createSpell

      @Nullable public @Nullable O2Spell createSpell(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull O2SpellType name, double wandC)
      This creates the spell projectile.
      Parameters:
      player - the player that cast the spell
      name - the name of the spell cast
      wandC - the wand check value for the held wand
      Returns:
      the spell that was created, or null if something failed