Class FLYING

java.lang.Object
net.pottercraft.ollivanders2.effect.O2Effect
net.pottercraft.ollivanders2.effect.FLYING
Direct Known Subclasses:
BROOM_FLYING

public class FLYING extends O2Effect
Effect that grants temporary flight ability to a player.

The FLYING effect enables the target player to fly for the specified duration. Each game tick, the effect checks the remaining duration and maintains flight state: while duration > 1 tick remains, the player can fly; on the final tick (duration ≤ 1), flight is disabled. Optional smoke particle effects can be displayed during flight by setting doSmokeEffect to true (default is false).

Mechanism:

  • Flight enabled each tick while duration > 1
  • Flight disabled on final tick (duration ≤ 1) before effect expires
  • Optional smoke particle effects each tick (disabled by default)
  • On removal: flight revoked unless player has Ollivanders2.admin permission
  • Admin players retain flight ability through spell/effect removal
  • Constructor Details

    • FLYING

      public FLYING(@NotNull @NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull @NotNull UUID pid)
      Constructor for creating a flight effect.

      Creates an effect that grants temporary flight ability to the target player. The effect will enable flight each tick while the duration remains above 1 tick, then disable flight on the final tick before expiring. Smoke effects are disabled by default (doSmokeEffect = false) but can be enabled by subclasses for visually distinctive flight mechanics.

      Parameters:
      plugin - a callback to the MC plugin
      duration - the duration of the effect in game ticks
      isPermanent - is this effect permanent (does not age)
      pid - the unique ID of the player to grant flight
  • Method Details

    • checkEffect

      public void checkEffect()
      Enable flight while the effect is active and disable on final tick.

      Called each game tick. This method:

      1. Ages the effect (decrements duration)
      2. If target player not found: kills the effect
      3. If duration > 1 (effect still active):
        • Enables flight (setAllowFlight(true))
        • Plays smoke effect each tick if doSmokeEffect is true
      4. If duration ≤ 1 (final tick):
        • Disables flight (setAllowFlight(false))
        • Effect expires naturally on next tick
      Specified by:
      checkEffect in class O2Effect
    • doRemove

      public void doRemove()
      Revoke flight ability when the effect is removed (unless player is an admin).

      Called when the flight effect expires or is manually killed. This method checks if the player has the "Ollivanders2.admin" permission:

      • Non-admin players: flight ability is revoked (setAllowFlight(false) and setFlying(false))
      • Admin players: flight ability is preserved - admins can retain flight through spell/effect removal

      This allows server admins to maintain flight privileges when flight-granting spells expire.

      Specified by:
      doRemove in class O2Effect