Bukkit Runnables - Best Practice

Discussion in 'Plugin Development' started by CheeserEats, Feb 3, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    CheeserEats

    Hi there guys, I am working on an effects plugin and have been working with Bukkit runnables, I want to know what some of the best practises are for using them. I am getting some sort of bug here with this code:
    Code:
        new BukkitRunnable() {
                public void run() {
                    for (Projectile e : getServer().getWorld("world").getEntitiesByClass(Snowball.class)) {
                        if (e.getShooter() instanceof Player) {
                                            Player player = (Player) e.getShooter();
                        if (player.getInventory().getItemInMainHand().getItemMeta().getLore().contains(
                                ChatColor.WHITE + "Spell: " + ChatColor.GRAY + "Minor Frost I " + ChatColor.DARK_PURPLE +"")) {    
                            //EFFECT PART ONE
                            double t = 0;
                            t = t + 0.0;
                            Location loc = e.getLocation();
                            Vector direction = loc.getDirection().normalize();
                            double x = direction.getX() * t;
                            double y = direction.getY() * t; // ON ENTITY
                            double z = direction.getZ() * t;
                            loc.add(x,y,z);
                            e.getWorld().spawnParticle(Particle.CLOUD, loc, 0, 0, 0, 0, 1);
                            loc.subtract(x,y,z);
      
                        if (t > 30){
                            this.cancel();
                                }
                            } else {
                                return;
                            }
                    } else {
                        this.cancel();
                    }
                }
                    return;
            }
        }.runTaskTimer(this, 0, 2);
    I am not sure if I am overloading the server with particles meaning its some sort of memory issue or what it is, is there any tips to optimize this? Cheers
     
    Last edited by a moderator: Feb 3, 2022
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    Please use this section for development stuff.
    @CheeserEats See your other thread on how to fix the nullpointerexception.
     
Thread Status:
Not open for further replies.

Share This Page