How do I refer to a target player in a FOR statement?

Discussion in 'Plugin Development' started by ForbiddenGaming, Oct 15, 2015.

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

    ForbiddenGaming

    Lets say for example I use this code (sender is already defined, trying to refer to a player in a for statement, resulting in a particleeffect playing):
    Code:
    
    public boolean onCommand(CommandSender p, Command cmd, String commandLabel, String[] args) {
      
    for (Player player : Bukkit.getServer().getPlayer(args[0])) {
       ParticleEffect.WATER_SPLASH.display(10, 15, 0, 0, 0, sender.getLocation().add(0, 0, 0), 25);
    }
    }
    
     
    Last edited: Oct 16, 2015
  2. Offline

    rbrick

    May want to start with examples that would work to begin with...
     
  3. Offline

    oceantheskatr

    The way you've set up your server, Bukkit.getServer().getPlayer(args[0]) would only return the one player specified, provided it's a valid player. As rbrick said, please specifiy what you're trying to do with greater detail.
     
  4. Offline

    ForbiddenGaming

  5. Offline

    567legodude

    @ForbiddenGaming To me it looks like you are trying to play a particle effects on a loop.
    If that's the case then you want to use a repeating task.
    Save a BukkitTask somewhere, and whenever you want to stop the effect get that task and call cancel() on it.
     
  6. Offline

    PixelBeaver

    567legodude makes a good point. If you do not understand how to do that, however, you can write your code like this:
    Code:
    for (Player p : Bukkit.getOnlinePlayers()) {
    if (p.getName().equalsIgnoreCase("username")) {
    ParticleEffect.WATER_SPLASH.display(10, 15, 0, 0, 0, sender.getLocation().add(0, 0, 0), 25);
    }
    }
    I am typing this from my phone, so I may not have written this write, so correct me if I'm wrong!
     
Thread Status:
Not open for further replies.

Share This Page