Class AGGRESSION
The AGGRESSION effect causes a player to periodically (every 10 seconds / 200 ticks) attack nearby entities and provoke creatures to target them. The effect has an aggressionLevel (1-10) that acts as a probability threshold: on each trigger, a random value (0-9) is compared against aggressionLevel. If random < aggressionLevel, the effect activates.
Attack Mechanism: When activated, the effect:
- Selects a random living entity within 3 blocks
- Applies damage equal to: currentHealth / randomDivisor where randomDivisor is 2, 3, or 4
- Respects WorldGuard PVP and damage animal flags
- Provokes all creatures within 6 blocks to target the aggressed player
This effect is permanent and cannot be modified via setPermanent(). Use kill() to remove it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe cooldown period between aggression checks in game ticks (120 ticks = 6 seconds).Fields inherited from class net.pottercraft.ollivanders2.effect.O2Effect
affectedPlayerText, duration, effectType, informousText, kill, legilimensText, p, permanent, targetID -
Constructor Summary
ConstructorsConstructorDescriptionAGGRESSION(@NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull UUID pid) Constructor for creating an aggression effect. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck the effect and periodically attack nearby entities and provoke creatures.voiddoRemove()Perform cleanup when this aggression effect is removed.voidsetAggressionLevel(int level) Set the aggression level and update the effect's probability.voidsetPermanent(boolean perm) Override to prevent external modification of permanent status.Methods inherited from class net.pottercraft.ollivanders2.effect.O2Effect
age, getAffectedPlayerText, getInformousText, getLegilimensText, getMaxDuration, getMinDuration, getRemainingDuration, getTargetID, isKilled, isPermanent, kill
-
Field Details
-
cooldownLimit
public static final int cooldownLimitThe cooldown period between aggression checks in game ticks (120 ticks = 6 seconds).The aggression effect checks for activation every 120 ticks (6 seconds). When the cooldown reaches 0, an attack probability check is performed, then the cooldown is reset.
- See Also:
-
-
Constructor Details
-
AGGRESSION
public AGGRESSION(@NotNull @NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull @NotNull UUID pid) Constructor for creating an aggression effect.Creates a permanent aggression effect that causes the player to periodically attack nearby entities and provoke mobs. The aggressionLevel is set from the duration parameter and controls the probability of attacks (1-10 range).
- Parameters:
plugin- a callback to the MC pluginduration- the aggression level (1-10), which will be clamped to valid rangeisPermanent- ignored - aggression is always permanentpid- the unique ID of the affected player
-
-
Method Details
-
checkEffect
public void checkEffect()Check the effect and periodically attack nearby entities and provoke creatures.This method executes once per tick and performs the following:
- Ages the effect by 1 tick (note: effect is permanent, so this doesn't cause expiration)
- Every 200 ticks (10 seconds), performs an action check:
- Generates random value 0-9
- If random < aggressionLevel: damages a random nearby entity (within 3 blocks) and provokes all creatures within 6 blocks to target the player
- Specified by:
checkEffectin classO2Effect
-
setAggressionLevel
public void setAggressionLevel(int level) Set the aggression level and update the effect's probability.Sets the aggressionLevel (1-10) which controls the probability of attacks on each trigger. The duration field is automatically updated to match, maintaining synchronization for serialization.
- Parameters:
level- the aggression level, will be clamped to range 1-10
-
setPermanent
public void setPermanent(boolean perm) Override to prevent external modification of permanent status.This effect is always permanent and cannot be modified via this method. The override is necessary because AGGRESSION must always remain permanent during the player's session. Use kill() to remove the effect instead.
- Overrides:
setPermanentin classO2Effect- Parameters:
perm- ignored - effect is always permanent
-
doRemove
public void doRemove()Perform cleanup when this aggression effect is removed.The default implementation does nothing, as aggression effects do not require special cleanup. The effect is removed from the player's effect list when kill() is called.
-