Added give-potion-effect effect

This commit is contained in:
Auxilor
2021-07-24 00:34:24 +01:00
parent 8c7f106b83
commit 494dde808a
2 changed files with 54 additions and 0 deletions

View File

@@ -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.

View File

@@ -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
)
);
}
}