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