Solved Repeating a task with BukkitRunnable

Discussion in 'Plugin Development' started by BarraBaja, Oct 24, 2021.

  1. Offline

    BarraBaja

    I'm trying to create a special snowball that works like a smoke bomb, spawning vision-obstructing particles for a set amount of time. After failing with For loops, I stumbled across BukkitRunnables but (probably due to my inexperience with Java) I couldn't get it working.

    This is the whole class:
    Code:
    package me.barrabaja.armasespeciales;
    import me.barrabaja.armasespeciales.Items.ItemManager;
    import org.bukkit.Particle;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.entity.ThrowableProjectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.scheduler.BukkitRunnable;
    
    
    public class BombaHumo implements Listener {
    
        Main plugin;
    
        public BombaHumo(Main plugin){
            this.plugin = plugin;
        }
    
        @EventHandler
        public void humo (ProjectileHitEvent e){
            if (e.getEntity() instanceof Snowball) {
                ThrowableProjectile s = (Snowball) e.getEntity();
                Player p = (Player) s.getShooter();
                if (s.getItem().getItemMeta().equals(ItemManager.humo.getItemMeta())) {
                    for (int i = 0; i < 10; i++) {
                        new BukkitRunnable(){
                            public void run(){
                                p.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, s.getLocation(),20 , 5, 3, 5);
                            }
                        }.runTaskTimer(plugin, 0L, 20L);
                    }
                }
            }
        }
    }
    I'm pretty sure I did a lot of things wrong here, so any help is super helpful!
     

Share This Page