Class O2Prophecy

java.lang.Object
net.pottercraft.ollivanders2.divination.O2Prophecy

public class O2Prophecy extends Object
Represents a scheduled divination prophecy with delayed effect execution.

An O2Prophecy encapsulates all the information needed to execute a prophecy at a future time: the target player, the magical effect to apply, the accuracy rating, and the scheduled execution time. Prophecies are processed each game tick: when the time reaches zero, the prophecy is "fulfilled" by applying the magical effect to the target player. The accuracy rating determines whether the prophecy actually succeeds when its time arrives—a random check compares the prophecy's accuracy against a random 0-99 roll.

Prophecies can be handled in two ways:

  • Online Target: If the target player is online when the prophecy is fulfilled, the effect is applied directly and a broadcast message announces the prophecy's outcome.
  • Offline Target: If the target player is offline, the prophecy is stashed and automatically re-executed when the player logs back in.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Maximum accuracy percentage a prophecy can have.
  • Constructor Summary

    Constructors
    Constructor
    Description
    O2Prophecy(@NotNull Ollivanders2 plugin, @NotNull O2EffectType effectType, @NotNull String message, @NotNull UUID targetID, @NotNull UUID prophetID, long delayTime, int effectDuration, int accuracy)
    Constructor for creating a new divination prophecy.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    age()
    Decrement the prophecy time by 1 game tick.
    void
    Execute this prophecy and apply its magical effect to the target player.
    int
    Get the duration of the effect from this prophecy
    @NotNull O2EffectType
    Get the effect this prophecy causes.
    Get the prophecy message, i.e.
    @NotNull UUID
    Get the ID of player who made this prophecy
    @NotNull UUID
    Get the ID of target player for this prophecy
    long
    Get the time until this prophecy happens
    boolean
    Is this prophecy expired/killed
    void
    Mark this prophecy as expired and prevent further processing.

    Methods inherited from class java.lang.Object

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

    • maxAccuracy

      public static final int maxAccuracy
      Maximum accuracy percentage a prophecy can have. Used to clamp prophecy accuracy in the constructor. Represents a 99% success rate.
      See Also:
  • Constructor Details

    • O2Prophecy

      public O2Prophecy(@NotNull @NotNull Ollivanders2 plugin, @NotNull @NotNull O2EffectType effectType, @NotNull @NotNull String message, @NotNull @NotNull UUID targetID, @NotNull @NotNull UUID prophetID, long delayTime, int effectDuration, int accuracy)
      Constructor for creating a new divination prophecy.

      Creates a prophecy with the given parameters. Accuracy is automatically clamped to 0-99 range. Once created, the prophecy will be managed by O2Prophecies and processed each game tick.

      Parameters:
      plugin - a reference to the plugin for API access
      effectType - the magical effect that will be applied if the prophecy succeeds
      message - the human-readable prophecy message displayed to players
      targetID - the unique ID of the target player who will receive the effect
      prophetID - the unique ID of the prophet (caster) for notification purposes
      delayTime - the number of game ticks until the prophecy is fulfilled
      effectDuration - the duration of the effect in game ticks (600-12000 typical)
      accuracy - the success probability (0-99). Values outside this range are clamped
  • Method Details

    • getEffect

      @NotNull public @NotNull O2EffectType getEffect()
      Get the effect this prophecy causes.
      Returns:
      the effect type
    • getTargetID

      @NotNull public @NotNull UUID getTargetID()
      Get the ID of target player for this prophecy
      Returns:
      the target player's unique ID
    • getProphetID

      @NotNull public @NotNull UUID getProphetID()
      Get the ID of player who made this prophecy
      Returns:
      the prophet player's unique ID
    • getTime

      public long getTime()
      Get the time until this prophecy happens
      Returns:
      the time in game ticks
    • getDuration

      public int getDuration()
      Get the duration of the effect from this prophecy
      Returns:
      the duration in game ticks
    • getProphecyMessage

      public String getProphecyMessage()
      Get the prophecy message, i.e. "After the sun sets on the 3rd day, Fred will fall in to a deep sleep."
      Returns:
      the prophecy message
    • isKilled

      public boolean isKilled()
      Is this prophecy expired/killed
      Returns:
      true if killed, false otherwise
    • age

      public void age()
      Decrement the prophecy time by 1 game tick.

      Called by O2Prophecies.upkeep() each game tick to advance the prophecy countdown. When time reaches zero or below, the prophecy is ready to be fulfilled.

    • kill

      public void kill()
      Mark this prophecy as expired and prevent further processing.

      Once killed, the prophecy will not be fulfilled even if it was scheduled to be, and will be removed from the prophecy lists during the next O2Prophecies.upkeep() call.

    • fulfill

      public void fulfill()
      Execute this prophecy and apply its magical effect to the target player.

      This method handles the complete prophecy fulfillment workflow:

      1. Checks if the prophecy has already been killed/expired; returns early if so
      2. Locates the target player on the server
      3. If target is offline: stashes the prophecy for later execution when the player logs in
      4. If target is online: performs an accuracy check by comparing the prophecy's accuracy against a random 0-99 roll
      5. On success (accuracy > roll): instantiates the magical effect and applies it to the target, then broadcasts a message to all players announcing the prophecy's fulfillment
      6. On failure (accuracy ≤ roll): sends a message to the prophet informing them the prophecy failed
      7. Marks the prophecy as killed to prevent further execution

      The accuracy check is probabilistic: a prophecy with 50% accuracy has a 50% chance of success, and a prophecy with 99% accuracy has a 99% chance of success.