Commits
Wesley Wolfe authored 78e2441ca5e
1 1 | package org.bukkit.command.defaults; |
2 2 | |
3 + | import java.util.Collection; |
3 4 | import java.util.List; |
4 5 | |
5 6 | import org.apache.commons.lang.Validate; |
6 7 | import org.bukkit.Bukkit; |
7 8 | import org.bukkit.command.CommandSender; |
8 9 | import org.bukkit.entity.Player; |
9 10 | |
10 11 | import com.google.common.collect.ImmutableList; |
11 12 | |
12 13 | public class ListCommand extends VanillaCommand { |
16 17 | this.usageMessage = "/list"; |
17 18 | this.setPermission("bukkit.command.list"); |
18 19 | } |
19 20 | |
20 21 | |
21 22 | public boolean execute(CommandSender sender, String currentAlias, String[] args) { |
22 23 | if (!testPermission(sender)) return true; |
23 24 | |
24 25 | StringBuilder online = new StringBuilder(); |
25 26 | |
26 - | Player[] players = Bukkit.getOnlinePlayers(); |
27 + | final Collection<? extends Player> players = Bukkit.getOnlinePlayers(); |
27 28 | |
28 29 | for (Player player : players) { |
29 30 | // If a player is hidden from the sender don't show them in the list |
30 31 | if (sender instanceof Player && !((Player) sender).canSee(player)) |
31 32 | continue; |
32 33 | |
33 34 | if (online.length() > 0) { |
34 35 | online.append(", "); |
35 36 | } |
36 37 | |
37 38 | online.append(player.getDisplayName()); |
38 39 | } |
39 40 | |
40 - | sender.sendMessage("There are " + players.length + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online.toString()); |
41 + | sender.sendMessage("There are " + players.size() + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online.toString()); |
41 42 | |
42 43 | return true; |
43 44 | } |
44 45 | |
45 46 | |
46 47 | public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { |
47 48 | Validate.notNull(sender, "Sender cannot be null"); |
48 49 | Validate.notNull(args, "Arguments cannot be null"); |
49 50 | Validate.notNull(alias, "Alias cannot be null"); |
50 51 | |