diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/Effects.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/Effects.java index a8d4525..be8841d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/Effects.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/Effects.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableList; import com.willfp.ecoweapons.effects.effects.EffectArrowStorm; import com.willfp.ecoweapons.effects.effects.EffectBleed; import com.willfp.ecoweapons.effects.effects.EffectConsoleCommand; +import com.willfp.ecoweapons.effects.effects.EffectGivePotionEffect; import com.willfp.ecoweapons.effects.effects.EffectRailgun; import com.willfp.ecoweapons.effects.effects.EffectSpawnHelper; import com.willfp.ecoweapons.effects.effects.EffectStrikeLightning; @@ -31,6 +32,7 @@ public class Effects { public static final Effect CONSOLE_COMMAND = new EffectConsoleCommand(); public static final Effect SPAWN_HELPER = new EffectSpawnHelper(); public static final Effect BLEED = new EffectBleed(); + public static final Effect GIVE_POTION_EFFECT = new EffectGivePotionEffect(); /** * Get effect matching name. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/effects/EffectGivePotionEffect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/effects/EffectGivePotionEffect.java new file mode 100644 index 0000000..3383a21 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoweapons/effects/effects/EffectGivePotionEffect.java @@ -0,0 +1,52 @@ +package com.willfp.ecoweapons.effects.effects; + +import com.willfp.eco.core.config.interfaces.JSONConfig; +import com.willfp.ecoweapons.effects.Effect; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; + +public class EffectGivePotionEffect extends Effect implements Listener { + public EffectGivePotionEffect() { + super("give-potion-effect"); + } + + @Override + public void handleMeleeAttack(@NotNull final Player player, + @NotNull final LivingEntity victim, + @NotNull final EntityDamageByEntityEvent event, + @NotNull final JSONConfig args) { + handle(player, victim, args); + } + + @Override + public void handleProjectileHitEntity(@NotNull final Player player, + @NotNull final LivingEntity victim, + @NotNull final Projectile projectile, + @NotNull final ProjectileHitEvent event, + @NotNull final JSONConfig args) { + handle(player, victim, args); + } + + private void handle(@NotNull final Player player, + @NotNull final LivingEntity victim, + @NotNull final JSONConfig args) { + PotionEffectType type = PotionEffectType.getByName(args.getString("potion").toUpperCase()); + int duration = args.getInt("duration"); + int strength = args.getInt("strength") - 1; + + victim.addPotionEffect( + new PotionEffect( + type, + duration, + strength + ) + ); + } +}