Solved Can't assign effect to Entity

Discussion in 'Plugin Development' started by SlimeyDerp, Mar 25, 2020.

  1. Offline

    SlimeyDerp

    Hello! I am developing an add-on for a plugin, and I have an item which I want to give whoever it hits a levitation, blindness and night vision ( Blindness + Night Vision = Total Blindness ) for 3 seconds, and then it will make the player explode.
    Code:
    @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent event) throws InterruptedException {
            if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) {
                Player attacker = (Player) event.getDamager();
                LivingEntity damaged = (LivingEntity) event.getEntity();
                if (SlimefunManager.isItemSimilar(attacker.getItemInHand(), ItemStacks.ETHERIAL_BALANCE_ROD_STACK, true)) {
                    damaged.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 3, 3));
                    damaged.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 3, 1));
                    damaged.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 3, 1));
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            damaged.getLocation().getWorld().createExplosion(damaged.getLocation(), 2F, false, false);
                        }
                    }.runTaskLater(this.plugin, 60);
                }
            }
        }
    
    The code works perfectly, up until the potion part. For some reason, Bukkit just skips this code completely and keeps going. So it makes the entity explode after 3 seconds, but it doesn't add the effects before it does it. I heard this is how you do it, but it doesn't work. Am I doing something wrong?

    EDIT: Nor the compiler, the IDE or the console throw any errors.
     
  2. Offline

    timtower Moderator Moderator

    @SlimeyDerp You do realize that that time is in ticks right?
    Bump up the time to like 300 for testing.
     
  3. Offline

    SlimeyDerp

    I don't understand. The explosion works fine. I know it's on ticks, so I added 60 ticks because 20 ticks = 1 second. I don't understand why I should modify something that works fine.
     
  4. Offline

    timtower Moderator Moderator

    @SlimeyDerp Talking about the time for the PotionEffects
     
  5. Offline

    SlimeyDerp

    OH! I didn't realize that! I'll go and test it, then close the thread if it fixes it!
     
    timtower likes this.

Share This Page