3

I am creating a Bukkit plugin where when a command is run, all player's balances will be modified (offline ones, too). I know it would be easy to do this with the online players, and using:

economy.withdrawPlayer(<player>, <amount>);

by simply looping through the online players, but could I somehow loop through ALL players and modify their account balance?

Dr_Derek
  • 73
  • 9

1 Answers1

1

You can use Bukkit.getOfflinePlayers() to get all Players that have joined a server. Example:

for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
    economy.withdrawPlayer(player, <amount>);
}
insou
  • 314
  • 1
  • 8
  • Thank you for this! Would I have to do a separate loop for online players as well? Also, would I have to make the variable type for 'player' as 'OfflinePlayer'? As Eclipse is telling me to do that. – Dr_Derek Dec 19 '15 at 21:32
  • 1
    Oops, yes my bad - that should be OfflinePlayer instead of Player. Also if you check the JavaDocs for Server#getOfflinePlayers it says that it gets every Player that has joined the server, so you only need to do getOfflinePlayers. – insou Dec 20 '15 at 19:34