Solved Particles play in one spot only

Discussion in 'Plugin Development' started by plisov, Apr 20, 2015.

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

    plisov

    I made a command that runs a particle repeatedly. I'm trying to make it follow the player. Right now, when I run the command, it plays the effect at the location the command was run and just stays there. Please help. Here is my code
    Code:
    if(cmd.getName().equalsIgnoreCase("particles")) {
                Player player = (Player) sender;
                Location loc = player.getLocation();
                Location loc1 = player.getLocation().add(0,1,0);
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                    @Override
                    public void run() {
                        loc.getWorld().playEffect(loc, Effect.HAPPY_VILLAGER, 50000);
                       
                    }
                   
                }, 0, 20);
            }
    
     
  2. Offline

    Konato_K

    @plisov You need to get the location of the player everytime run is called.
     
  3. Offline

    plisov

    Ah. Alright thanks. I got it to work. Here is the final code
    Code:
    if(cmd.getName().equalsIgnoreCase("particles")) {
                Player player = (Player) sender;
                Location loc = player.getLocation();
                Location loc1 = player.getLocation().add(0,1,0);
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                    @Override
                    public void run() {
                        for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                        loc.getWorld().playEffect(player.getLocation().add(0, 2, 0), Effect.HAPPY_VILLAGER, 50000);
                       
                        }
                    }
                   
                }, 0, 20);
            }
    
    But now it only plays 1 particle every like 2 seconds. Is there any way to running the same particle many times?
     
  4. @plisov The numbers at the end of the run() control when and how many times it is ran, I believe.
     
  5. Offline

    plisov

    Yup. Thanks so much guys.
     
  6. @plisov No problem, any time. Make sure to set the thread to solved by going to Thread Tools (at the top) > Edit Title > Prefix > Solved. See this for more information.
     
Thread Status:
Not open for further replies.

Share This Page