Solved Arrow Trails.

Discussion in 'Plugin Development' started by flash110, May 26, 2016.

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

    flash110

    cHello! For the past couple days I have been trying to make a plugin that lets you shoot arrows, and a particle trail for the arrows. I got the arrows and everything else to work, but I can not get the particles to spawn, I did a lot of debugging and I couldn't figure out the reason. All of the code is running at the proper times.
    Code:
    package me.flash110;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    public class Wither extends JavaPlugin implements Listener {
       
        public static ArrayList<String> players = new ArrayList<>();
        public static ArrayList<Projectile> arrows = new ArrayList<>();
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Effect();
            }
       
        @EventHandler
        public void click(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (p.getItemInHand().getType() == Material.GOLD_SWORD) {
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    p.sendMessage("You right-clicked!");
                    Vector v = p.getLocation().getDirection().multiply(2D);
                    Arrow a = (Arrow) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.ARROW);
                    a.setShooter(p);
                    a.setVelocity(v);
                    arrows.add(a);
                }
                else {
                    Vector v = p.getLocation().getDirection().multiply(2D);
                    WitherSkull ws = (WitherSkull) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.WITHER_SKULL);
                    ws.setVelocity(v);
                }
                if (players.size() >= 0) {
                }
            }
        }
       
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent e){
        if(e.getEntity() instanceof Arrow){
            Bukkit.broadcastMessage("Arrow should be removed");
            arrows.remove(e.getEntity());
        }
        }
        public void Effect() {
             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
               
                   @Override
                   public void run() {
                      for(Projectile arrow : arrows){
                               Location loc = arrow.getLocation();
                               String name = Bukkit.getServer().getServerName();
                               //NEED TO SPAWN PARTICLES HERE!
                               //For whatever reason I can not get it to work.
                          }
                       }
         
              }, 0, 1);
          }
    }
    
    It would be nice if anyone could explain or give me an example of what to put there, thanks!
     
  2. Offline

    Zombie_Striker

    @flash110
    I think the reason you cant spawn any particles is because you have not written anything to spawn particles. Please post what you have tried and we will help you from there.

    If you don't know how to spawn a particle, either Google "Bukkit help spawn particle" or look in the Resources forum for tutorials.
     
  3. Offline

    flash110

    Ok, I have tried this library which involves these two classes:
     
  4. Offline

    Zombie_Striker

    @flash110
    That utility is as inefficient as it is hard to read. Use the following line instead:
    Code:
    //For one player
    Player#playEffect(Location, Effect, 0);
    
    //For the whole server
    World#playEffect(Location, Effect, 0)
    
     
  5. Offline

    flash110

    oops

    I know you are probably cringing at this by now, but would this be right? (It doesn't work)
    Code:
    package me.flash110;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    public class Wither extends JavaPlugin implements Listener {
    
        public static ArrayList<String> players = new ArrayList<>();
        public static ArrayList<Projectile> arrows = new ArrayList<>();
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Effect();
            }
    
        @EventHandler
        public void click(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (p.getItemInHand().getType() == Material.GOLD_SWORD) {
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    p.sendMessage("You right-clicked!");
                    Vector v = p.getLocation().getDirection().multiply(2D);
                    Arrow a = (Arrow) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.ARROW);
                    a.setShooter(p);
                    a.setVelocity(v);
                    arrows.add(a);
                }
                else {
                    Vector v = p.getLocation().getDirection().multiply(2D);
                    WitherSkull ws = (WitherSkull) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.WITHER_SKULL);
                    ws.setVelocity(v);
                }
                if (players.size() >= 0) {
                }
            }
        }
    
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent e){
        if(e.getEntity() instanceof Arrow){
            Bukkit.broadcastMessage("Arrow should be removed");
            arrows.remove(e.getEntity());
        }
        }
        public void Effect() {
             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
             
                   @Override
                   public void run() {
                      for(Projectile arrow : arrows){
                               Location loc = arrow.getLocation();
                               String name = Bukkit.getServer().getServerName();
                               arrow.getWorld().playEffect(loc, org.bukkit.Effect.FIREWORKS_SPARK, 10);
                          }
                       }
       
              }, 0, 1);
          }
    }
    
    And please do not give me the learn Java answer, I know enough of the Java Language for my needs, I just do not know the Bukkit API.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. Offline

    Zombie_Striker

    Your problem is with the last value. There is no firework with datatype '10', so it does not display anything You need to change that last value from 10 to 0.
     
  7. Offline

    flash110

    Didn't work ;-; Effect Method:
    Code:
    public void Effect() {
             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
               
                   @Override
                   public void run() {
                      for(Projectile arrow : arrows){
                               Location loc = arrow.getLocation();
                               String name = Bukkit.getServer().getServerName();
                               arrow.getWorld().playEffect(loc, org.bukkit.Effect.FIREWORKS_SPARK, 0);
                          }
                       }
         
              }, 0, 1);
          }
    Should that still work in version 1.8? I did exactly as you said, and once again no particles. I know it isn't your fault that it is not working and I am just trying to figure out why it isn't working... It looks perfectly fine to me. Can you find any other reason that the particles are not spawning on the arrows as they fly through the air?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page