Class SLEEPING

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

public class SLEEPING extends O2Effect
Sleep induction effect that forces the affected player into a deep sleep state.

SLEEPING is a temporary debilitating effect that simulates sleep for the target player since Minecraft does not support actual sleep actions for non-player-initiated sleeps. When activated, the effect immobilizes the player, tilts their head downward (pitch = 45 degrees), applies the SLEEP_SPEECH effect to replace their chat with sleep sounds, and applies the IMMOBILIZE effect to prevent all movement and interaction. The sleep state can be broken by applying the AWAKE effect, which automatically kills this effect. When removed, all secondary effects (speech replacement and immobilization) are cleaned up and the player is notified of awakening.

Sleep Configuration:

  • Secondary effects: SLEEP_SPEECH (sleep vocalizations) and IMMOBILIZE (paralysis)
  • Head tilt: downward pitch angle of 45 degrees
  • Sleep state tracking: boolean flag to detect sleep initialization
  • Breaking condition: AWAKE effect application
  • Permanent: false (temporary effect with time-based expiration)
  • Detection text: "is affected by an unnatural sleep"
See Also:
  • Field Details

    • SLEEP_MESSAGE

      public static final String SLEEP_MESSAGE
      Message sent to the player when they fall asleep.
      See Also:
    • SLEEP_WAKEUP_MESSAGE

      public static final String SLEEP_WAKEUP_MESSAGE
      Message sent to the player when they wake up.
      See Also:
  • Constructor Details

    • SLEEPING

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

      Creates a sleep effect that forces the target player into a deep sleep state. On the first checkEffect() call, the player will be immobilized, their head will be tilted downward, sleep vocalizations will begin, and they will receive a notification. The sleep persists until the duration expires or the AWAKE effect is applied to break the sleep.

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

    • checkEffect

      public void checkEffect()
      Age the sleep effect and apply sleep state once per effect lifetime.

      Called each game tick. This method first ages the effect by 1 tick. Then it checks if the sleep state has been initialized via the sleeping flag. If not, it calls playerSleep() once to initialize the sleep state (applying secondary effects, head tilt, and messaging). The sleep persists each tick until the effect duration expires or is explicitly removed.

      Specified by:
      checkEffect in class O2Effect
    • doRemove

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

      When the sleep effect is removed, this method cleans up the secondary effects (SLEEP_SPEECH and IMMOBILIZE) that were applied during sleep. The player is notified of awakening and the sleeping flag is reset. If the player is offline, cleanup is gracefully skipped.

      Specified by:
      doRemove in class O2Effect