Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BanListCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.UUID;
6 
7 import org.apache.commons.lang.Validate;
8 import org.bukkit.BanEntry;
9 import org.bukkit.BanList;
10 import org.bukkit.Bukkit;
11 import org.bukkit.ChatColor;
12 import org.bukkit.OfflinePlayer;
14 import org.bukkit.util.StringUtil;
15 
16 import com.google.common.collect.ImmutableList;
17 
18 public class BanListCommand extends VanillaCommand {
19  private static final List<String> BANLIST_TYPES = ImmutableList.of("ips", "players");
20 
21  public BanListCommand() {
22  super("banlist");
23  this.description = "View all players banned from this server";
24  this.usageMessage = "/banlist [ips|players]";
25  this.setPermission("bukkit.command.ban.list");
26  }
27 
28  @Override
29  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
30  if (!testPermission(sender)) return true;
31 
32  BanList.Type banType = BanList.Type.NAME;
33  if (args.length > 0) {
34  if (args[0].equalsIgnoreCase("ips")) {
35  banType = BanList.Type.IP;
36  } else if (!args[0].equalsIgnoreCase("players")) {
37  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
38  return false;
39  }
40  }
41 
42  StringBuilder message = new StringBuilder();
43  BanEntry[] banlist = Bukkit.getBanList(banType).getBanEntries().toArray(new BanEntry[0]);
44 
45  for (int x = 0; x < banlist.length; x++) {
46  if (x != 0) {
47  if (x == banlist.length - 1) {
48  message.append(" and ");
49  } else {
50  message.append(", ");
51  }
52  }
53 
54  message.append(banlist[x].getTarget());
55  }
56 
57  sender.sendMessage("There are " + banlist.length + " total banned players:");
58  sender.sendMessage(message.toString());
59  return true;
60  }
61 
62  @Override
63  public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
64  Validate.notNull(sender, "Sender cannot be null");
65  Validate.notNull(args, "Arguments cannot be null");
66  Validate.notNull(alias, "Alias cannot be null");
67 
68  if (args.length == 1) {
69  return StringUtil.copyPartialMatches(args[0], BANLIST_TYPES, new ArrayList<String>(BANLIST_TYPES.size()));
70  }
71  return ImmutableList.of();
72  }
73 }
boolean testPermission(CommandSender target)
static< TextendsCollection<?superString > T copyPartialMatches(final String token, final Iterable< String > originals, final T collection)
Definition: StringUtil.java:24
void sendMessage(String message)
void setPermission(String permission)
static BanList getBanList(BanList.Type type)
Definition: Bukkit.java:471
Definition: BanEntry.java:41
Set< BanEntry > getBanEntries()