Class O2Prophecy
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
FieldsModifier and TypeFieldDescriptionstatic final intMaximum accuracy percentage a prophecy can have. -
Constructor Summary
ConstructorsConstructorDescriptionO2Prophecy(@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 TypeMethodDescriptionvoidage()Decrement the prophecy time by 1 game tick.voidfulfill()Execute this prophecy and apply its magical effect to the target player.intGet the duration of the effect from this prophecy@NotNull O2EffectTypeGet the effect this prophecy causes.Get the prophecy message, i.e.@NotNull UUIDGet the ID of player who made this prophecy@NotNull UUIDGet the ID of target player for this prophecylonggetTime()Get the time until this prophecy happensbooleanisKilled()Is this prophecy expired/killedvoidkill()Mark this prophecy as expired and prevent further processing.
-
Field Details
-
maxAccuracy
public static final int maxAccuracyMaximum 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 accesseffectType- the magical effect that will be applied if the prophecy succeedsmessage- the human-readable prophecy message displayed to playerstargetID- the unique ID of the target player who will receive the effectprophetID- the unique ID of the prophet (caster) for notification purposesdelayTime- the number of game ticks until the prophecy is fulfilledeffectDuration- 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
Get the effect this prophecy causes.- Returns:
- the effect type
-
getTargetID
Get the ID of target player for this prophecy- Returns:
- the target player's unique ID
-
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
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:
- Checks if the prophecy has already been killed/expired; returns early if so
- Locates the target player on the server
- If target is offline: stashes the prophecy for later execution when the player logs in
- If target is online: performs an accuracy check by comparing the prophecy's accuracy against a random 0-99 roll
- 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
- On failure (accuracy ≤ roll): sends a message to the prophet informing them the prophecy failed
- 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.
-