Class PotionEffectSuper

java.lang.Object
net.pottercraft.ollivanders2.effect.O2Effect
net.pottercraft.ollivanders2.effect.PotionEffectSuper
Direct Known Subclasses:
BLINDNESS, CONFUSION, FIRE_RESISTANCE, HARM, HEAL, HEALTH_BOOST, HUNGER, LUCK, NIGHT_VISION, POISON, REGENERATION, SATIATION, SLOWNESS, SPEED, SPEED_SPEEDIER, SPEED_SPEEDIEST, STRENGTH, UNLUCK, WATER_BREATHING, WEAKNESS

public abstract class PotionEffectSuper extends O2Effect
Parent class for effects that apply Minecraft potion effects to players.

PotionEffectSuper provides a potion effect application mechanism that applies effects immediately and then expires. Potion effects are applied in checkEffect() and the effect kills itself in the same tick.

Duration Mechanism:

Potion effects are applied with a duration clamped to a valid range:
  • Minimum duration: 2400 ticks (2 minutes)
  • Maximum duration: 6000 ticks (5 minutes)
  • The duration specified in the constructor is clamped to this range

Effect Configuration: Subclasses set potionEffectType to specify which Minecraft potion effect (POISON, WEAKNESS, etc.) to apply, and strength to set the amplifier level of the effect (1 is normal strength).

  • Constructor Details

    • PotionEffectSuper

      public PotionEffectSuper(@NotNull @NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull @NotNull UUID pid)
      Constructor for creating a potion effect.

      Creates an effect that will apply a Minecraft potion effect immediately and expire in a single game tick. Subclasses should initialize potionEffectType and strength fields before the effect is added to a player's effect list.

      Parameters:
      plugin - a reference to the plugin
      duration - the duration in ticks, snapped to min of 2 minutes, max of 5 minutes
      isPermanent - ignored - potion effects cannot be permanent
      pid - the unique ID of the target player
  • Method Details

    • checkEffect

      public void checkEffect()
      Apply the potion effect immediately and expire.

      This method executes in a single game tick and performs the following:

      1. Creates a new potion effect with the specified type, duration, and strength (amplifier)
      2. Applies the potion effect to the target player (initialized in O2Effect constructor)
      3. Kills the effect so it doesn't persist beyond the single tick

      Example: A POISON effect with strength 2 will create a poison effect with amplifier 2 and the duration specified when the effect was created (clamped to 2400-6000 ticks).

      Specified by:
      checkEffect in class O2Effect
    • setStrength

      public void setStrength(int s)
      Set the amplifier strength of this potion effect.

      Sets the strength (amplifier level) of the potion effect that will be applied to the player. A value of 1 represents normal strength. Higher values increase the effect's potency.

      Parameters:
      s - a positive integer representing the amplifier level (1 = normal, 2 = enhanced, etc.)
    • getStrength

      public int getStrength()
      Get the strength for this potion effect
      Returns:
      the potion strength
    • getPotionEffectType

      public org.bukkit.potion.PotionEffectType getPotionEffectType()
      Get the PotionEffectType this PotionEffect effect adds
      Returns:
      the PotionEffectType
    • setPermanent

      public void setPermanent(boolean perm)
      Potion effects cannot ever be permanent
      Overrides:
      setPermanent in class O2Effect
      Parameters:
      perm - ignored - potion effects are always temporary