001 package org.bukkit.command.defaults; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 import java.util.UUID; 006 007 import org.apache.commons.lang.Validate; 008 import org.bukkit.BanEntry; 009 import org.bukkit.BanList; 010 import org.bukkit.Bukkit; 011 import org.bukkit.ChatColor; 012 import org.bukkit.OfflinePlayer; 013 import org.bukkit.command.CommandSender; 014 import org.bukkit.util.StringUtil; 015 016 import com.google.common.collect.ImmutableList; 017 018 public class BanListCommand extends VanillaCommand { 019 private static final List<String> BANLIST_TYPES = ImmutableList.of("ips", "players"); 020 021 public BanListCommand() { 022 super("banlist"); 023 this.description = "View all players banned from this server"; 024 this.usageMessage = "/banlist [ips|players]"; 025 this.setPermission("bukkit.command.ban.list"); 026 } 027 028 @Override 029 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 030 if (!testPermission(sender)) return true; 031 032 BanList.Type banType = BanList.Type.NAME; 033 if (args.length > 0) { 034 if (args[0].equalsIgnoreCase("ips")) { 035 banType = BanList.Type.IP; 036 } else if (!args[0].equalsIgnoreCase("players")) { 037 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 038 return false; 039 } 040 } 041 042 StringBuilder message = new StringBuilder(); 043 BanEntry[] banlist = Bukkit.getBanList(banType).getBanEntries().toArray(new BanEntry[0]); 044 045 for (int x = 0; x < banlist.length; x++) { 046 if (x != 0) { 047 if (x == banlist.length - 1) { 048 message.append(" and "); 049 } else { 050 message.append(", "); 051 } 052 } 053 054 message.append(banlist[x].getTarget()); 055 } 056 057 sender.sendMessage("There are " + banlist.length + " total banned players:"); 058 sender.sendMessage(message.toString()); 059 return true; 060 } 061 062 @Override 063 public List<String> tabComplete(CommandSender sender, String alias, String[] args) { 064 Validate.notNull(sender, "Sender cannot be null"); 065 Validate.notNull(args, "Arguments cannot be null"); 066 Validate.notNull(alias, "Alias cannot be null"); 067 068 if (args.length == 1) { 069 return StringUtil.copyPartialMatches(args[0], BANLIST_TYPES, new ArrayList<String>(BANLIST_TYPES.size())); 070 } 071 return ImmutableList.of(); 072 } 073 }