#can't apply potion effect to living entity

1 messages · Page 1 of 1 (latest)

daring beacon
#

package wands.wands;

import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class WandOfSouls implements Listener {
private Plugin plugin;
public WandOfSouls(final Plugin plugin) {this.plugin = plugin;}

@EventHandler
public void hitEnemy(EntityDamageByEntityEvent event) {
    if (!(event.getEntity() instanceof Player) && event.getDamager() instanceof Player) {
        if (((Player) event.getDamager()).getInventory().getItemInMainHand().getItemMeta().getLore().contains("Strike your foes with lightning.")) {
            Location loc = event.getEntity().getLocation();
            World world = event.getEntity().getWorld();
            world.strikeLightning(loc);
        }
        else if (((Player) event.getDamager()).getInventory().getItemInMainHand().getItemMeta().getLore().contains("Strike your foes into another dimension!")) {
            LivingEntity target = (LivingEntity) event.getEntity();
            target.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION,2,2));
            Bukkit.getScheduler().runTaskLater(plugin, () -> {
                event.getEntity().getWorld().playEffect(event.getEntity().getLocation(), Effect.ENDER_SIGNAL, 0);
                ((LivingEntity) event.getEntity()).setHealth(0);
            }, 40L); // amount to wait in ticks , 20 ticks = 1 second
        }
    }
}

}

#

code for the class im working in

#

all other code above adding potion effect and below works

#

but the entity just doesnt seem to want to levitate

worn nova
daring beacon
#

alright

#

after doing that it was run and i noticed my mistake xD

#

the effect is played for duration in ticks

#

not seconds

worn nova