Class O2Effect
- Direct Known Subclasses:
AGGRESSION,ANIMAGUS_INCANTATION,AWAKE,BABBLING,BURNING,DANCING_FEET,FAST_LEARNING,FLYING,HIGHER_SKILL,IMMOBILIZE,IMPROVED_BOOK_LEARNING,LYCANTHROPY_RELIEF,MUCUS,MUTED_SPEECH,O2EffectAntidoteSuper,PlayerChangeSizeSuper,PotionEffectAntidoteSuper,PotionEffectSuper,ShapeShiftSuper,ShieldSpellEffect,SLEEPING,SUSPENSION,TICKLING,WEALTH
An O2Effect represents a temporary or semi-permanent magical alteration of a player's behavior or abilities. Effects are managed by the player effects system and processed each game tick. While O2Effect itself cannot permanently modify a player's core data, some effects may persist indefinitely until explicitly removed or until a specific in-game action cancels them.
Effect Lifecycle:
- Effect is created with a duration (in game ticks)
- checkEffect() is called every game tick to apply the effect's behavior
- age() is called to decrement the duration counter
- When duration reaches zero (or effect is manually killed), doRemove() is called for cleanup
- Effect is removed from the player's effect list
Event Integration: Subclasses can override event handler methods (doOnPlayerInteractEvent, doOnPlayerChatEvent, etc.) to respond to specific server events. These methods are called automatically when their corresponding events occur and the effect is active.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe message shown to a player when they become affected by this effect.intThe remaining duration of this effect, measured in game ticks.The type of magical effect this instance represents.protected StringThe text displayed by information detection spells (e.g., Informous) if this effect can be detected.protected booleanFlag indicating this effect has been marked for removal.protected StringThe text displayed by mind-reading detection spells (e.g., Legilimens) if this effect can be detected.protected final Ollivanders2Reference to the plugin for accessing configuration, logging, and server API.protected booleanFlag indicating whether this effect is permanent.protected UUIDThe unique identifier of the player affected by this effect. -
Constructor Summary
ConstructorsConstructorDescriptionO2Effect(@NotNull Ollivanders2 plugin, int durationInTicks, boolean isPermanent, @NotNull UUID pid) Constructor for creating a new magical effect. -
Method Summary
Modifier and TypeMethodDescriptionvoidage(int i) Decrement the effect's duration by the specified amount.abstract voidExecute this effect's behavior for the current game tick.abstract voiddoRemove()Perform cleanup when this effect is removed from the player.@Nullable StringGet the message to display to a player when this effect is applied.Get the informous text for this effectGet the legiliments text for this effectintGet the maximum duration, in ticks, for this effect typeintGet the minimum duration, in ticks, for this effect typeintGet the ticks remaining for this effect@NotNull UUIDGet the unique identifier of the player affected by this effect.booleanisKilled()Check whether this effect has been marked for removal.booleanCheck whether this effect is permanent.voidkill()This kills the effect.voidsetPermanent(boolean perm) Override default permanent setting for an effect.
-
Field Details
-
effectType
The type of magical effect this instance represents. Used to identify the specific effect and is set to BABBLING as a safe default. -
duration
public int durationThe remaining duration of this effect, measured in game ticks. One game tick = 1/20 of a second. One Minecraft day = 24000 ticks (~20 real minutes). Decremented each tick by age(). When it reaches zero or below, the effect is automatically killed. Permanent effects have a duration of -1 and do not age. -
p
Reference to the plugin for accessing configuration, logging, and server API. -
kill
protected boolean killFlag indicating this effect has been marked for removal. When true, the effect will be removed from the player's effect list on the next upkeep cycle. -
permanent
protected boolean permanentFlag indicating whether this effect is permanent. Permanent effects do not age (duration stays at -1) and are only removed when explicitly killed or when a specific game action triggers their removal via doRemove(). -
targetID
The unique identifier of the player affected by this effect. -
informousText
The text displayed by information detection spells (e.g., Informous) if this effect can be detected. This string is the predicate of a sentence that starts with the player's name and should not include ending punctuation. Example: "feels unnaturally tired" (resulting in "Player feels unnaturally tired"). If null, the effect is not detectable by information spells. -
legilimensText
The text displayed by mind-reading detection spells (e.g., Legilimens) if this effect can be detected. This string is the predicate of a sentence that starts with the player's name and should not include ending punctuation. Example: "feels aggressive" (resulting in "Player feels aggressive"). If null, the effect is not detectable by mind-reading spells. -
affectedPlayerText
The message shown to a player when they become affected by this effect. This is sent as a chat message to the target player immediately after the effect is applied. If null, no message is sent to the affected player.
-
-
Constructor Details
-
O2Effect
public O2Effect(@NotNull @NotNull Ollivanders2 plugin, int durationInTicks, boolean isPermanent, @NotNull @NotNull UUID pid) Constructor for creating a new magical effect.Creates an effect with the given duration and target player. If the duration is negative, the effect is automatically set to permanent (duration = -1). Non-permanent effects with durations shorter than minDuration are automatically extended to meet the minimum.
IMPORTANT: If you change this method signature, be sure to update all reflection code that instantiates effects using this constructor (e.g., O2Prophecy.fulfill()).
- Parameters:
plugin- reference to the plugin for API accessdurationInTicks- the duration in game ticks. Negative values create permanent effectsisPermanent- whether this effect is permanent (ie. does not age) or notpid- the unique ID of the target player for this effect
-
-
Method Details
-
getMinDuration
public int getMinDuration()Get the minimum duration, in ticks, for this effect type- Returns:
- the minimum duration
-
getMaxDuration
public int getMaxDuration()Get the maximum duration, in ticks, for this effect type- Returns:
- the maximum duration
-
getRemainingDuration
public int getRemainingDuration()Get the ticks remaining for this effect- Returns:
- duration remaining for this effect
-
getLegilimensText
Get the legiliments text for this effect- Returns:
- the legilimens text
-
getInformousText
Get the informous text for this effect- Returns:
- the informous text
-
age
public void age(int i) Decrement the effect's duration by the specified amount.Called by the player effects system each game tick to age the effect. Permanent effects are not aged and immediately return. Non-permanent effects have their duration decremented; when duration drops below zero, the effect is automatically killed.
- Parameters:
i- the number of ticks to subtract from the effect's remaining duration
-
setPermanent
public void setPermanent(boolean perm) Override default permanent setting for an effect.- Parameters:
perm- true if this is permanent, false otherwise
-
kill
public void kill()This kills the effect. -
getTargetID
Get the unique identifier of the player affected by this effect.Returns a copy of the target UUID to prevent external modification of the original.
- Returns:
- the unique ID of the target player
-
checkEffect
public abstract void checkEffect()Execute this effect's behavior for the current game tick.This method is called once per game tick for active effects on a player. Subclasses should override this method to implement the effect's specific behavior (e.g., applying potion effects, restricting actions, modifying movement, etc.). Subclasses should call age() in this method to ensure the effect ages and eventually expires.
Implementation Note: This method is called within the main server thread on each tick. Keep execution time short to avoid lag.
-
doRemove
public abstract void doRemove()Perform cleanup when this effect is removed from the player.Called when the effect is about to be removed from the player's effect list (either due to expiration, being killed, or a player logout). Subclasses should override this method to undo any permanent changes made by the effect, such as removing potion effects, restoring abilities, or updating the player's state.
-
isPermanent
public boolean isPermanent()Check whether this effect is permanent.Permanent effects have a duration of -1 and are not aged by the age() method. They persist until explicitly killed or removed by doRemove().
- Returns:
- true if the effect is permanent, false if it will eventually expire
-
isKilled
public boolean isKilled()Check whether this effect has been marked for removal.Once killed, the effect will be removed from the player's effect list on the next upkeep cycle.
- Returns:
- true if the effect has been killed, false otherwise
-
getAffectedPlayerText
Get the message to display to a player when this effect is applied.This message is sent to the target player as a chat message immediately after the effect is applied. If no message is desired, subclasses can leave affectedPlayerText as null, and no message will be sent.
- Returns:
- the message to show, or null if no message should be displayed
-