Class AWAKE
The AWAKE effect is a temporary counter-effect that keeps a player awake and prevents them from entering a sleeping state. This is typically used to counteract sleep-inducing spells or effects that would otherwise put the player to sleep. The effect persists for its specified duration and automatically expires when the duration reaches zero.
Effect Lifecycle:
- On each game tick, checkEffect() checks if the player is sleeping and wakes them if needed
- If the player has a SLEEPING effect active, AWAKE removes it (AWAKE overrides SLEEPING)
- PlayerBedEnterEvent is cancelled to prevent the player from entering beds
- When the effect expires, the player can naturally sleep again; no cleanup required
Interaction with SLEEPING:
- AWAKE and SLEEPING are mutually exclusive - only one can be active at a time
- If SLEEPING detects AWAKE, it immediately kills itself
- If AWAKE detects SLEEPING, it removes that effect and wakes the player
- This bidirectional interaction prevents conflicting sleep states
Detection:
- Detectable by the Informous spell with text: "is unnaturally alert"
- Detectable by the Legilimens spell with text: "is unnaturally alert"
- See Also:
-
Field Summary
Fields inherited from class net.pottercraft.ollivanders2.effect.O2Effect
affectedPlayerText, duration, effectType, informousText, kill, legilimensText, p, permanent, targetID -
Constructor Summary
ConstructorsConstructorDescriptionAWAKE(@NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull UUID pid) Constructor for creating an awake-state effect. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck the awake effect each game tick and wake sleeping players.voiddoRemove()Perform cleanup when the awake effect is removed.Methods inherited from class net.pottercraft.ollivanders2.effect.O2Effect
age, getAffectedPlayerText, getInformousText, getLegilimensText, getMaxDuration, getMinDuration, getRemainingDuration, getTargetID, isKilled, isPermanent, kill, setPermanent
-
Constructor Details
-
AWAKE
public AWAKE(@NotNull @NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull @NotNull UUID pid) Constructor for creating an awake-state effect.Creates an effect that prevents the player from sleeping for the specified duration. Sets both information and mind-reading detection texts to indicate the player is unnaturally alert.
- Parameters:
plugin- a callback to the MC pluginduration- the duration of the awake state in game ticksisPermanent- is this effect permanent (does not age)pid- the unique ID of the player to keep awake
-
-
Method Details
-
checkEffect
public void checkEffect()Check the awake effect each game tick and wake sleeping players.Called each game tick to decrement the effect's duration and ensure the player remains awake. This method performs three key functions:
- Ages the effect by 1 tick (when duration reaches zero, the effect is automatically killed)
- Removes any active SLEEPING effect to enforce AWAKE override (only if SLEEPING is currently active)
- Wakes the player if they are sleeping (skipped in test mode to avoid MockBukkit limitations)
The active waking mechanism ensures that even if a SLEEPING effect was applied before AWAKE, the player will be immediately woken on the next game tick. This works in conjunction with doOnPlayerBedEnterEvent() which prevents new sleep attempts. In test mode, the wakeup() call is skipped because MockBukkit does not implement player sleep functionality.
- Specified by:
checkEffectin classO2Effect
-
doRemove
public void doRemove()Perform cleanup when the awake effect is removed.The default implementation does nothing, as the awake effect is passive and has no state to clean up. Simply allowing the player to sleep again is handled automatically by effect removal.
-