Class AGGRESSION

java.lang.Object
net.pottercraft.ollivanders2.effect.O2Effect
net.pottercraft.ollivanders2.effect.AGGRESSION

public class AGGRESSION extends O2Effect
Effect that causes a player to impulsively harm nearby entities and provoke mob 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 Details

    • cooldownLimit

      public static final int cooldownLimit
      The 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 plugin
      duration - the aggression level (1-10), which will be clamped to valid range
      isPermanent - ignored - aggression is always permanent
      pid - 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:

      1. Ages the effect by 1 tick (note: effect is permanent, so this doesn't cause expiration)
      2. 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:
      checkEffect in class O2Effect
    • 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:
      setPermanent in class O2Effect
      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.

      Specified by:
      doRemove in class O2Effect