Class O2Effect

java.lang.Object
net.pottercraft.ollivanders2.effect.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

public abstract class O2Effect extends Object
Abstract base class for all magical effects that can be applied to players.

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:

  1. Effect is created with a duration (in game ticks)
  2. checkEffect() is called every game tick to apply the effect's behavior
  3. age() is called to decrement the duration counter
  4. When duration reaches zero (or effect is manually killed), doRemove() is called for cleanup
  5. 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

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The message shown to a player when they become affected by this effect.
    int
    The remaining duration of this effect, measured in game ticks.
    The type of magical effect this instance represents.
    protected String
    The text displayed by information detection spells (e.g., Informous) if this effect can be detected.
    protected boolean
    Flag indicating this effect has been marked for removal.
    protected String
    The text displayed by mind-reading detection spells (e.g., Legilimens) if this effect can be detected.
    protected final Ollivanders2
    Reference to the plugin for accessing configuration, logging, and server API.
    protected boolean
    Flag indicating whether this effect is permanent.
    protected UUID
    The unique identifier of the player affected by this effect.
  • Constructor Summary

    Constructors
    Constructor
    Description
    O2Effect(@NotNull Ollivanders2 plugin, int durationInTicks, boolean isPermanent, @NotNull UUID pid)
    Constructor for creating a new magical effect.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    age(int i)
    Decrement the effect's duration by the specified amount.
    abstract void
    Execute this effect's behavior for the current game tick.
    abstract void
    Perform cleanup when this effect is removed from the player.
    @Nullable String
    Get the message to display to a player when this effect is applied.
    Get the informous text for this effect
    Get the legiliments text for this effect
    int
    Get the maximum duration, in ticks, for this effect type
    int
    Get the minimum duration, in ticks, for this effect type
    int
    Get the ticks remaining for this effect
    @NotNull UUID
    Get the unique identifier of the player affected by this effect.
    boolean
    Check whether this effect has been marked for removal.
    boolean
    Check whether this effect is permanent.
    void
    This kills the effect.
    void
    setPermanent(boolean perm)
    Override default permanent setting for an effect.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • effectType

      public O2EffectType 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 duration
      The 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

      protected final Ollivanders2 p
      Reference to the plugin for accessing configuration, logging, and server API.
    • kill

      protected boolean kill
      Flag 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 permanent
      Flag 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

      protected UUID targetID
      The unique identifier of the player affected by this effect.
    • informousText

      protected String 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

      protected String 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

      protected String 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 access
      durationInTicks - the duration in game ticks. Negative values create permanent effects
      isPermanent - whether this effect is permanent (ie. does not age) or not
      pid - 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

      public String getLegilimensText()
      Get the legiliments text for this effect
      Returns:
      the legilimens text
    • getInformousText

      public String 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

      @NotNull public @NotNull UUID 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

      @Nullable public @Nullable String 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