001 package org.bukkit.command.defaults; 002 003 import java.util.Collection; 004 import java.util.List; 005 006 import org.apache.commons.lang.Validate; 007 import org.bukkit.Bukkit; 008 import org.bukkit.command.CommandSender; 009 import org.bukkit.entity.Player; 010 011 import com.google.common.collect.ImmutableList; 012 013 public class ListCommand extends VanillaCommand { 014 public ListCommand() { 015 super("list"); 016 this.description = "Lists all online players"; 017 this.usageMessage = "/list"; 018 this.setPermission("bukkit.command.list"); 019 } 020 021 @Override 022 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 023 if (!testPermission(sender)) return true; 024 025 StringBuilder online = new StringBuilder(); 026 027 final Collection<? extends Player> players = Bukkit.getOnlinePlayers(); 028 029 for (Player player : players) { 030 // If a player is hidden from the sender don't show them in the list 031 if (sender instanceof Player && !((Player) sender).canSee(player)) 032 continue; 033 034 if (online.length() > 0) { 035 online.append(", "); 036 } 037 038 online.append(player.getDisplayName()); 039 } 040 041 sender.sendMessage("There are " + players.size() + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online.toString()); 042 043 return true; 044 } 045 046 @Override 047 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 048 Validate.notNull(sender, "Sender cannot be null"); 049 Validate.notNull(args, "Arguments cannot be null"); 050 Validate.notNull(alias, "Alias cannot be null"); 051 052 return ImmutableList.of(); 053 } 054 }