Class ConcealmentShieldSpell

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CAVE_INIMICUM, REPELLO_MUGGLETON

public abstract class ConcealmentShieldSpell extends ShieldSpell
Abstract base class for concealment shield spells that hide and restrict access to protected areas.

Concealment shield spells create protective barriers that:

  • Hide players inside the area from those outside (via visibility toggle)
  • Prevent certain entities from entering the protected area
  • Block entities outside from targeting players inside
  • Prevent chat from those outside reaching those inside
  • Optionally trigger proximity alarms when hostile entities approach

Subclasses customize behavior through abstract methods: canEnter(LivingEntity), canSee(LivingEntity), canHear(LivingEntity), canTarget(LivingEntity), and checkAlarm(LivingEntity).

Since:
2.21
See Also:
  • Field Details

    • alarmOnProximity

      protected boolean alarmOnProximity
      Whether this spell triggers proximity alarms when hostile entities approach.
    • proximityRadiusModifier

      protected int proximityRadiusModifier
      The distance (in blocks) beyond the spell radius that triggers proximity alarms. Extends the effective alarm radius outward from the spell's boundary.
    • proximityCooldownTimer

      protected int proximityCooldownTimer
      Current cooldown counter for proximity alarms. Prevents the alarm from triggering repeatedly. Decremented each tick when active, prevents new alarms when greater than zero.
    • proximityCooldownLimit

      protected final int proximityCooldownLimit
      The fixed duration (in ticks) of the proximity alarm cooldown (1 minute). Reset when a proximity alarm is triggered.
      See Also:
    • entryDenyMessages

      protected ArrayList<String> entryDenyMessages
      Messages displayed to players who attempt to enter but are denied access. One message is chosen randomly from this list each time entry is denied.
  • Constructor Details

    • ConcealmentShieldSpell

      public ConcealmentShieldSpell(@NotNull @NotNull Ollivanders2 plugin)
      Constructs a concealment spell from deserialized data at server start.

      Used only for loading saved spells from disk. Subclasses should not call this for spell casting - use the full constructor instead.

      Parameters:
      plugin - a callback to the MC plugin
    • ConcealmentShieldSpell

      public ConcealmentShieldSpell(@NotNull @NotNull Ollivanders2 plugin, @NotNull @NotNull UUID pid, @NotNull @NotNull org.bukkit.Location location, int radius, int duration)
      Constructs a new concealment shield spell cast by a player.

      Initializes the spell with the specified properties and immediately hides all players currently in the spell area (based on the canSee(LivingEntity) implementation).

      Parameters:
      plugin - a callback to the MC plugin
      pid - the UUID of the player who cast the spell
      location - the center location of the spell
      radius - the initial radius for this spell
      duration - the initial duration for this spell in ticks
  • Method Details

    • upkeep

      public void upkeep()
      Performs per-tick upkeep for this concealment spell.

      Ages the spell by one tick, decrements the proximity alarm cooldown timer, and kills the spell when duration reaches zero.

      Specified by:
      upkeep in class O2StationarySpell
    • getEntryDenyMessages

      public ArrayList<String> getEntryDenyMessages()
      Get the entry deny messages.
      Returns:
      the entry deny messages
    • hidePlayersInSpellArea

      protected void hidePlayersInSpellArea()
      Hides or shows players in the spell area based on visibility rules.

      Iterates through all players in the spell radius and toggles their visibility according to the toggleVisibility(Player) logic and canSee(LivingEntity) implementation.

    • toggleVisibility

      protected void toggleVisibility(@NotNull @NotNull org.bukkit.entity.Player player)
      Toggles the visibility of a specific player based on concealment rules.

      For each online player (viewer), hides or shows the target player based on:

      • Whether the target is inside the spell area
      • Whether the viewer can see into the spell area (via canSee(LivingEntity))
      • Whether the target has other invisibility effects

      Does not hide the target from themselves.

      Parameters:
      player - the player whose visibility to toggle
    • unhidePlayersInSpellArea

      protected void unhidePlayersInSpellArea()
      Shows all players in the spell area to other online players.

      Called when the spell ends to remove the concealment effect from all affected players.

    • unhidePlayer

      protected void unhidePlayer(@NotNull @NotNull org.bukkit.entity.Player player)
      Shows a player to all online players (removes concealment).

      Called when a player leaves the spell area or when the spell ends. Does not unhide players who have other invisibility effects.

      Parameters:
      player - the player to show
    • getAreaEntryDenialMessage

      @Nullable protected @Nullable String getAreaEntryDenialMessage()
      Gets a random entry denial message to display to players blocked from entering.

      Selects a random message from the configured entryDenyMessages list. Used when a player attempts to enter the spell area but fails the canEnter(LivingEntity) check.

      Returns:
      a random message from the configured list, or null if no messages are configured
    • doProximityCheck

      protected void doProximityCheck(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Checks and triggers a proximity alarm if conditions are met.

      Tests whether the entity meets alarm conditions via checkAlarm(LivingEntity) or checkAlarm(Player) and triggers proximityAlarm() if conditions match. Does nothing if the proximity alarm cooldown is active.

      Parameters:
      entity - the living entity that may trigger the alarm
    • isInProximity

      public boolean isInProximity(org.bukkit.Location alertLocation)
      Checks if a location is within the proximity alarm detection radius.

      The proximity radius extends proximityRadiusModifier blocks beyond the spell's boundary.

      Parameters:
      alertLocation - the location to check
      Returns:
      true if the location is within the proximity alarm radius, false otherwise
    • getProximityRadius

      public int getProximityRadius()
      The radius from the spell center for proximity checks for this spell
      Returns:
      the proximity radius
    • doesAlarmOnProximty

      public boolean doesAlarmOnProximty()
      Does this spell alarm on proximity?
      Returns:
      true if it alarms on proximity, false otherwise
    • handleEntityMove

      protected void handleEntityMove(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull org.bukkit.Location toLocation, @NotNull @NotNull org.bukkit.Location fromLocation)
      Handles visibility and proximity logic when an entity moves relative to the spell boundary.

      Called asynchronously after a player move event completes successfully. Handles three cases:

      • Entity entering: Re-evaluates visibility for all players in the area if entry is allowed
      • Entity leaving: Unhides the departing player to all viewers
      • Proximity check: Triggers proximity alarm if entity moves near the boundary

      Assumes the move event completed and entry restrictions have already been checked.

      Parameters:
      entity - the living entity that moved
      toLocation - the location the entity moved to
      fromLocation - the location the entity moved from
    • serializeSpellData

      @NotNull public @NotNull Map<String,String> serializeSpellData()
      Serializes concealment spell data for persistence.

      This base implementation returns an empty map. Subclasses can override to save spell-specific configuration like proximity alarm settings or custom messages.

      Returns:
      a map of serialized spell-specific data
    • deserializeSpellData

      public void deserializeSpellData(@NotNull @NotNull Map<String,String> spellData)
      Deserializes concealment spell data from storage.

      This base implementation does nothing. Subclasses can override to restore spell-specific configuration that was previously saved.

      Parameters:
      spellData - the map of saved spell-specific data
    • canHear

      protected abstract boolean canHear(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Determines if an entity outside the spell area can hear sounds from inside.

      Used by doOnAsyncPlayerChatEvent(AsyncPlayerChatEvent) to determine if chat from players inside should reach this entity.

      Parameters:
      entity - the entity outside the spell area to check (not null)
      Returns:
      true if the entity can hear conversations inside the spell area, false if sounds are concealed
    • canSee

      protected abstract boolean canSee(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Determines if an entity outside the spell area can see players inside.

      Used by toggleVisibility(Player) to determine whether to hide concealed players from this entity's view.

      Parameters:
      entity - the entity outside the spell area to check (not null)
      Returns:
      true if the entity can see players inside the spell area, false if players are hidden
    • canTarget

      public abstract boolean canTarget(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Determines if an entity outside the spell area can target players inside.

      Used by doOnEntityTargetEvent(EntityTargetEvent) to determine if targeting attempts from outside should succeed.

      Parameters:
      entity - the entity outside the spell area to check (not null)
      Returns:
      true if the entity can target players inside the spell area, false if targeting is blocked
    • canEnter

      public abstract boolean canEnter(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Determines if an entity can enter the spell area.

      Used by doOnPlayerMoveEvent(PlayerMoveEvent) to determine if a player attempting to cross the spell boundary should be allowed entry.

      Parameters:
      entity - the entity attempting to enter the spell area (not null)
      Returns:
      true if the entity can enter the spell area, false if entry is blocked
    • checkAlarm

      protected abstract boolean checkAlarm(@NotNull @NotNull org.bukkit.entity.Player player)
      Checks if a player outside the spell area should trigger a proximity alarm.

      Called by doProximityCheck(LivingEntity) when an entity moves within the proximity alarm radius. Allows subclasses to implement spell-specific alarm conditions.

      Parameters:
      player - the player outside the spell area at proximity distance (not null)
      Returns:
      true if the alarm conditions are met, false otherwise
    • checkAlarm

      protected abstract boolean checkAlarm(@NotNull @NotNull org.bukkit.entity.LivingEntity entity)
      Checks if a non-player entity outside the spell area should trigger a proximity alarm.

      Called by doProximityCheck(LivingEntity) when an entity moves within the proximity alarm radius. Allows subclasses to implement spell-specific alarm conditions.

      Parameters:
      entity - the non-player entity outside the spell area at proximity distance (not null)
      Returns:
      true if the alarm conditions are met, false otherwise
    • proximityAlarm

      protected abstract void proximityAlarm()
      Performs the proximity alarm action for this spell.

      Called by doProximityCheck(LivingEntity) when proximity alarm conditions are met. Typically, sends a message or triggers an effect to alert players inside the spell area.