Class O2StationarySpells

java.lang.Object
net.pottercraft.ollivanders2.stationaryspell.O2StationarySpells
All Implemented Interfaces:
org.bukkit.event.Listener

public class O2StationarySpells extends Object implements org.bukkit.event.Listener
Manager for all active and inactive stationary spells in the game.

This class handles lifecycle management of stationary spells, including creation, activation, deactivation, and persistence. It acts as an event listener that broadcasts Bukkit events to all active stationary spells, allowing them to respond to world events. Stationary spells are area-of-effect spells that persist at specific locations and affect players and entities within their radius.

Key responsibilities:

  • Managing the collection of all stationary spells
  • Broadcasting Bukkit events to active spells for custom behavior
  • Serialization and persistence of spell data to disk
  • Spell lifecycle management (loading, upkeep, removal)
  • Constructor Details

    • O2StationarySpells

      public O2StationarySpells(@NotNull @NotNull Ollivanders2 plugin)
      Constructs a new O2StationarySpells manager.
      Parameters:
      plugin - the Ollivanders2 plugin instance (not null)
  • Method Details

    • onEnable

      public void onEnable()
      Initializes the stationary spells system when the plugin enables.

      Loads previously saved stationary spells from disk and registers this manager as a Bukkit event listener to receive world events for distribution to active spells.

    • onDisable

      public void onDisable()
      Cleanup when the plugin disables.

      Called when the Ollivanders2 plugin is being shut down. The O2StationarySpells manager persists all active stationary spell data to disk. Stationary spells (such as enchanted areas or persistent magical effects) are serialized and saved so they can be restored when the server restarts, maintaining long-term magical effects in the world.

      Saved Data:

      • All active stationary spells in their current state
      • Spell location, duration, and radius information
      • Caster UUID and spell-specific properties
      • Data is persisted as JSON via GsonDAO for restoration on server startup
      See Also:
    • onPlayerMove

      public void onPlayerMove(@NotNull @NotNull org.bukkit.event.player.PlayerMoveEvent event)
      Broadcasts a player move event to all active stationary spells.

      Fired when a player moves to a new block. Stationary spells can use this to detect player movement within their area of effect.

      Parameters:
      event - the player move event
    • onCreatureSpawnEvent

      public void onCreatureSpawnEvent(@NotNull @NotNull org.bukkit.event.entity.CreatureSpawnEvent event)
      Handle when creatures spawn
      Parameters:
      event - the creature spawn event
    • onEntityTargetEvent

      public void onEntityTargetEvent(@NotNull @NotNull org.bukkit.event.entity.EntityTargetEvent event)
      Handle when entities target
      Parameters:
      event - the event
    • onAsyncPlayerChatEvent

      public void onAsyncPlayerChatEvent(@NotNull @NotNull org.bukkit.event.player.AsyncPlayerChatEvent event)
      Handle when players chat
      Parameters:
      event - the event
    • onBlockBreakEvent

      public void onBlockBreakEvent(@NotNull @NotNull org.bukkit.event.block.BlockBreakEvent event)
      Handle block break event
      Parameters:
      event - the event
    • onEntityBreakDoorEvent

      public void onEntityBreakDoorEvent(@NotNull @NotNull org.bukkit.event.entity.EntityBreakDoorEvent event)
      Handle entity break door event
      Parameters:
      event - the event
    • onEntityChangeBlockEvent

      public void onEntityChangeBlockEvent(@NotNull @NotNull org.bukkit.event.entity.EntityChangeBlockEvent event)
      Handle entity break door event
      Parameters:
      event - the event
    • onEntityInteractEvent

      public void onEntityInteractEvent(@NotNull @NotNull org.bukkit.event.entity.EntityInteractEvent event)
      Handle entity interact event
      Parameters:
      event - the event
    • onEntityDamageEvent

      public void onEntityDamageEvent(@NotNull @NotNull org.bukkit.event.entity.EntityDamageEvent event)
      Handle entity damage
      Parameters:
      event - the event
    • onPlayerInteractEvent

      public void onPlayerInteractEvent(@NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Handle entity damage event
      Parameters:
      event - the event
    • onOllivandersApparateByNameEvent

      public void onOllivandersApparateByNameEvent(@NotNull @NotNull OllivandersApparateByNameEvent event)
      Handle apparate by name event
      Parameters:
      event - the event
    • onOllivandersApparateByCoordinatesEvent

      public void onOllivandersApparateByCoordinatesEvent(@NotNull @NotNull OllivandersApparateByCoordinatesEvent event)
      Handle apparate by coordinate event
      Parameters:
      event - the event
    • onEntityTeleportEvent

      public void onEntityTeleportEvent(@NotNull @NotNull org.bukkit.event.entity.EntityTeleportEvent event)
      Handle entity teleport events
      Parameters:
      event - the event
    • onPlayerTeleportEvent

      public void onPlayerTeleportEvent(@NotNull @NotNull org.bukkit.event.player.PlayerTeleportEvent event)
      Handle player teleport events
      Parameters:
      event - the event
    • onEntityCombustEvent

      public void onEntityCombustEvent(@NotNull @NotNull org.bukkit.event.entity.EntityCombustEvent event)
      Handle entity combust by block events
      Parameters:
      event - the event
    • onSpellProjectileMoveEvent

      public void onSpellProjectileMoveEvent(@NotNull @NotNull OllivandersSpellProjectileMoveEvent event)
      Handle spell projectile move events
      Parameters:
      event - the event
    • onPlayerJoinEvent

      public void onPlayerJoinEvent(@NotNull @NotNull org.bukkit.event.player.PlayerJoinEvent event)
      Handle world load events
      Parameters:
      event - the event
    • onItemDespawnEvent

      public void onItemDespawnEvent(@NotNull @NotNull org.bukkit.event.entity.ItemDespawnEvent event)
      Handle item despawn events
      Parameters:
      event - the item despawn event
    • onEntityPickupItemEvent

      public void onEntityPickupItemEvent(@NotNull @NotNull org.bukkit.event.entity.EntityPickupItemEvent event)
      Handle items being picked up by entities
      Parameters:
      event - the event
    • onInventoryItemPickupEvent

      public void onInventoryItemPickupEvent(@NotNull @NotNull org.bukkit.event.inventory.InventoryPickupItemEvent event)
      Handle items being picked up by things like hoppers
      Parameters:
      event - the event
    • onPlayerDeathEvent

      public void onPlayerDeathEvent(@NotNull @NotNull org.bukkit.event.entity.PlayerDeathEvent event)
      Handle player deal events
      Parameters:
      event - the player death event
    • onBlockFromToEvent

      public void onBlockFromToEvent(@NotNull @NotNull org.bukkit.event.block.BlockFromToEvent event)
      Handle block from to events (like water or lava flowing)
      Parameters:
      event - the event
    • onPlayerBucketEmptyEvent

      public void onPlayerBucketEmptyEvent(@NotNull @NotNull org.bukkit.event.player.PlayerBucketEmptyEvent event)
      Handle player bucket empty events
      Parameters:
      event - the event
    • onProjectileLaunchEvent

      public void onProjectileLaunchEvent(@NotNull @NotNull org.bukkit.event.entity.ProjectileLaunchEvent event)
      Handle projectile launch events
      Parameters:
      event - the event
    • onProjectileHitEvent

      public void onProjectileHitEvent(@NotNull @NotNull org.bukkit.event.entity.ProjectileHitEvent event)
      Handle projectile hit events
      Parameters:
      event - the event
    • addStationarySpell

      public void addStationarySpell(@NotNull @NotNull O2StationarySpell spell)
      Adds a new stationary spell to the manager.

      The spell is added to the internal list and will immediately be eligible to receive Bukkit events if it is marked as active.

      Parameters:
      spell - the stationary spell to add (not null)
    • removeStationarySpell

      public void removeStationarySpell(@NotNull @NotNull O2StationarySpell spell)
      Marks a stationary spell for removal.

      Instead of immediately removing the spell, this marks it as killed and allows the next upkeep() cycle to clean it up. This prevents iterator corruption during event broadcasts.

      Parameters:
      spell - the stationary spell to remove (not null)
    • getActiveStationarySpells

      @NotNull public @NotNull List<O2StationarySpell> getActiveStationarySpells()
      Return a list of active stationary spells
      Returns:
      a list of active stationary spells
    • getStationarySpellsAtLocation

      @NotNull public @NotNull List<O2StationarySpell> getStationarySpellsAtLocation(@NotNull @NotNull org.bukkit.Location targetLoc)
      Finds all stationary spells (active or inactive) at a specific location.

      Checks all spells in the manager to see if the given location falls within their radius of effect, regardless of whether the spells are currently active or marked for removal.

      Parameters:
      targetLoc - the location to check (not null)
      Returns:
      a list of all stationary spells containing this location, empty if none found
    • getActiveStationarySpellsAtLocationByType

      @NotNull public @NotNull List<O2StationarySpell> getActiveStationarySpellsAtLocationByType(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull O2StationarySpellType spellType)
      Finds all active stationary spells of a specific type at a location.

      Returns only spells that are both active and of the specified type, located at the given position. Useful for checking if a specific spell effect is active at a location.

      Parameters:
      location - the location to check (not null)
      spellType - the type of spell to search for (not null)
      Returns:
      a list of active spells of that type at the location, empty if none found
    • checkLocationForStationarySpell

      public boolean checkLocationForStationarySpell(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull O2StationarySpellType stationarySpellType)
      Check for a specific type of stationary spell at a location
      Parameters:
      location - the location to check
      stationarySpellType - the stationary spell type to check for
      Returns:
      true if spell of that type exists at that location, false otherwise
    • isInsideOf

      public boolean isInsideOf(@NotNull @NotNull O2StationarySpellType stationarySpell, @NotNull @NotNull org.bukkit.Location loc)
      Determine if the location is inside a stationary spell area.
      Parameters:
      stationarySpell - the stationary spell to check
      loc - the location to check
      Returns:
      true if the location is inside this stationary spell, false otherwise
    • upkeep

      public void upkeep()
      Runs the upkeep cycle for all active spells and removes killed spells.

      Called periodically (e.g., each server tick) to allow spells to update their state (decrement duration, apply effects, etc.) and to clean up spells marked for removal. Uses a copy of the spell list to safely remove spells during iteration.

    • saveO2StationarySpells

      public void saveO2StationarySpells()
      Persists all stationary spells to disk as JSON.

      Called when the server shuts down to save the current state of all spells. Spells can be restored on the next server start via loadO2StationarySpells().

    • loadO2StationarySpells

      public void loadO2StationarySpells()
      Loads saved stationary spells from disk.

      Called on plugin startup to restore spells that were persisted during the previous shutdown. If no saved spell data exists, an empty list is created.

    • createStationarySpellByType

      @Nullable public @Nullable O2StationarySpell createStationarySpellByType(@NotNull @NotNull O2StationarySpellType spellType)
      Creates a new instance of a stationary spell by its type using reflection.

      Instantiates the spell class associated with the given spell type. The spell is created with default/uninitialized properties and will be inactive by default. Additional properties (location, duration, radius, caster) must be set after creation via setter methods.

      Parameters:
      spellType - the type of spell to create (not null)
      Returns:
      a new spell instance, or null if instantiation fails