Setting scoreboard to one player equals all players in the server?

Discussion in 'Plugin Development' started by IconByte, Mar 29, 2015.

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

    IconByte

    Hello, I am doing that simple checking and setting the scoreboard, but it still sets to everyone in the server...
    Code:
                for (Player onlinePlayers : Bukkit.getOnlinePlayers()) {
                    if (onlinePlayers.getWorld() == Bukkit.getWorld("arena")) {
                        onlinePlayers.setScoreboard(plugin.Scoreboard1);
                    }
                }
     
    Last edited: Mar 29, 2015
  2. use .equals instead of ==
     
    OfficerDeveloper likes this.
  3. Offline

    IconByte

    Thanks, but it didn't affect anything. :/
    Current code:
    Code:
               for (Player onlinePlayers : Bukkit.getOnlinePlayers()) {
                   if (onlinePlayers.getWorld().equals(Bukkit.getWorld("arena")))) {
                       onlinePlayers.setScoreboard(plugin.Scoreboard1);
                   }
               }
     
  4. The for loop will return ALL online players, not just one player. If you want ONE player, create a player object. Also, checking to see what world they are in, won't affect that the for loop calls ALL online players on the server... So thats why @FishyLP's suggestion didn't change.
     
  5. @OfficerDeveloper
    ... Youre not right I think
    He looped through every onlinePlayer.
    Then he checked if the current Player in the loop is in the world. The code after it will only run, if the if-condition is true
     
  6. Offline

    RainoBoy97

    Compare the world name instead.
     
  7. Offline

    SuchSwegMuchWow

  8. @FisheyLP I am right, that check will return all the players in that world, not one specific player. So thats why it is not working the way he wants it to.
     
Thread Status:
Not open for further replies.

Share This Page