Class O2Spells
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:
- If a global allow list is defined, only globally allowed spells can be cast
- Check zone-specific allow lists (WORLD, WORLD_GUARD, CUBOID) - if found, only zone-allowed spells pass
- Check zone-specific disallow lists - if spell is found in any zone's disallow list, deny it
- Check global disallow list - if spell is found, deny it
- If no restrictions apply, allow the spell
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the spell and increment cast count@Nullable O2SpellcreateSpell(@NotNull org.bukkit.entity.Player player, @NotNull O2SpellType name, double wandC) This creates the spell projectile.Get all the active spell projectilesstatic List<O2SpellType> Get all loaded spells@Nullable O2SpellTypegetSpellTypeByName(@NotNull String name) Get a spell type by name.booleanisLoaded(@NotNull O2SpellType spellType) Verify this spell type is loaded.booleanisSpellTypeAllowed(@NotNull org.bukkit.Location location, @NotNull O2SpellType spellType) Check if a spell is allowed based on zone configvoidLoad the zone config for spellsvoidCleanup when the plugin disables.voidonEnable()Initializes spell data when the plugin is enabled.voidupkeep()Updates all active spell projectiles for one game tick.
-
Field Details
-
wandlessSpells
Wandless spells
-
-
Constructor Details
-
O2Spells
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
- Loads all available spell types from
-
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.
- Calls
-
getAllSpellTypes
Get all loaded spells- Returns:
- a list of all loaded spell types
-
getSpellTypeByName
Get a spell type by name.- Parameters:
name- the name of the spell or potion- Returns:
- the type if found, null otherwise
-
isLoaded
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 spellspellType- 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 spellspell- the spell cast
-
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 spellname- the name of the spell castwandC- the wand check value for the held wand- Returns:
- the spell that was created, or null if something failed
-