Solved enderpearl trail

Discussion in 'Spigot Plugin Development' started by yhl, Aug 4, 2018.

  1. yhl

    yhl

    How would I add a trail to an enderpearl projectile?
     
  2. FrostedSnowman

    Resource Staff

    on launch run a task that checks if Entity#isValid and then spawns a particle at the enderpearls location. cancel the task when Entity#isValid is false
     
    • Agree Agree x 1
  3. yhl

    yhl

    I'm pretty sure I did it wrong

    Code (Java):
        public void pearlTrail(){

            new BukkitRunnable(){

                @Override
                public void run(){

                    for(World world : Bukkit.getWorlds()){
                        for(Entity e: world.getEntities()){
                            if(e.isValid()){
                                world.createExplosion(e.getLocation(),10);
                            }
                        }
                    }

                }
            }.runTaskTimerAsynchronously(plugin, 0, 1);
     
  4. I think you should use ProjectileLaunchEvent and if the launched entity is enderpearl then create your task ('e' stands for the event, so use e.getEntity().isValid()).
     
  5. Wait, that's going to blow up every entity in the world every tick? :D

    Don't really ever use runTaskTimerAsynchronously (or any of the async methods) unless you really know what you're doing- you can't really use any Bukkit API methods from in there.
     
  6. yhl

    yhl

    Okay well I got it to work with a method I found but I want it to only work when I throw it, but when it lands I still have a trail on it (it's on me)

    Code (Java):
    public class Methods {

        JHubCore plugin = JHubCore.plugin;


        public void pearlTrail(){

            new BukkitRunnable(){

                @Override
                public void run(){

                    for(World world : Bukkit.getWorlds()){
                        for(Entity e: world.getEntities()){
                            if(e.isValid()){
                                particle(e.getLocation());
                            }
                        }
                    }

                }
            }.runTaskTimerAsynchronously(plugin, 0, 1);

        }

        private void particle(Location loc) {
            PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.FLAME, true, (float) loc.getX(),
                    (float) loc.getY(), (float) loc.getZ(), 0, 0, 0, 0, 15, null);
            for (Player p : Bukkit.getOnlinePlayers()) {
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
            }
        }

    }
     
  7. FrostedSnowman

    Resource Staff

    like i said, you need to cancel it.

    Code (Java):

                            if(e.isValid()){
                                particle(e.getLocation());
                                return;
                            }
                            this.cancel();
    also you are doing it for every entity. check to make sure it's an enderpearl
     
  8. yhl

    yhl

    doesnt need to be cancelled but I forgot to check if the entity was an enderpearl lol thanks!