Class SUSPENSION

java.lang.Object
net.pottercraft.ollivanders2.effect.O2Effect
net.pottercraft.ollivanders2.effect.SUSPENSION

public class SUSPENSION extends O2Effect
Suspension effect that hoists the affected player into the air and maintains them there.

SUSPENSION is a debilitating effect that suspends the target player at eye level by teleporting them to a suspended location. The effect applies two additional permanent effects to maintain the suspension state: FLYING (to prevent falling due to gravity) and IMMOBILIZE (to prevent any movement that could break the suspension). The player's original location is recorded and restored when the effect is removed. This effect replaced the original LEVICORPUS implementation.

Suspension Configuration:

  • Suspension height: at player eye level
  • Head pitch: 45 degrees (downward tilt)
  • Secondary effects: FLYING (permanent, prevents falling) and IMMOBILIZE (permanent, prevents movement)
  • Suspension initialization: delayed 5 ticks after effect activation to allow secondary effects to activate
  • Suspension state: tracked via boolean flag
  • Velocity events: cancelled to maintain suspension stability
  • Constructor Details

    • SUSPENSION

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

      Creates a suspension effect that will hoist the target player into the air on the first checkEffect() call. The player will be teleported to a suspended location and secondary effects (FLYING and IMMOBILIZE) will be applied to maintain the suspension state. The original location is recorded for restoration when the effect is removed.

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

    • checkEffect

      public void checkEffect()
      Age the suspension effect and initialize suspension on first tick.

      Called each game tick. This method ages the effect counter and checks if the player has been suspended yet via the suspended flag. If not, it performs the suspension initialization in two steps:

      1. Immediately adds the secondary effects (FLYING and IMMOBILIZE) to allow them to activate
      2. Delays the actual suspension (teleport and setFlying) by 5 ticks to ensure the secondary effects have time to start working before the player is moved

      This delay is necessary because the FLYING effect must be initialized before calling setFlying(true), otherwise the player could briefly fall before the effect prevents gravity.

      Specified by:
      checkEffect in class O2Effect
    • doRemove

      public void doRemove()
      Clean up the suspension effect and restore the player to normal state.

      When the suspension effect is removed, this method teleports the player back to their original location and removes the secondary effects (FLYING and IMMOBILIZE) that were applied to maintain suspension. If the player is offline, cleanup is gracefully skipped.

      Specified by:
      doRemove in class O2Effect
    • isSuspended

      public boolean isSuspended()
      Check if the player is currently suspended in the air.

      Returns true after the player has been hoisted into the air via the suspend() method. This flag is used to ensure the suspension mechanism runs exactly once per effect.

      Returns:
      true if the player has been suspended, false if the suspension is still pending