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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.bukkit.command.defaults;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class WhitelistCommand extends VanillaCommand {
public WhitelistCommand() {
super("whitelist");
this.description = "Prevents the specified player from using this server";
this.usageMessage = "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)";
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (badPerm(sender, "reload")) return true;
Bukkit.reloadWhitelist();
Command.broadcastCommandMessage(sender, "Reloaded white-list from file");
return true;
} else if (args[0].equalsIgnoreCase("on")) {
if (badPerm(sender, "enable")) return true;
Bukkit.setWhitelist(true);
Command.broadcastCommandMessage(sender, "Turned on white-listing");
return true;
} else if (args[0].equalsIgnoreCase("off")) {
if (badPerm(sender, "disable")) return true;
Bukkit.setWhitelist(false);
Command.broadcastCommandMessage(sender, "Turned off white-listing");
return true;
} else if (args[0].equalsIgnoreCase("list")) {
if (badPerm(sender, "list")) return true;
StringBuilder result = new StringBuilder();
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
if (result.length() > 0) {
result.append(" ");
}
result.append(player.getName());
}
sender.sendMessage("White-listed players: " + result.toString());
return true;
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("add")) {
if (badPerm(sender, "add")) return true;
Bukkit.getOfflinePlayer(args[1]).setWhitelisted(true);
Command.broadcastCommandMessage(sender, "Added " + args[1] + " to white-list");
return true;
} else if (args[0].equalsIgnoreCase("remove")) {
if (badPerm(sender, "remove")) return true;
Bukkit.getOfflinePlayer(args[1]).setWhitelisted(false);
Command.broadcastCommandMessage(sender, "Removed " + args[1] + " from white-list");
return true;
}
}
sender.sendMessage(ChatColor.RED + "Correct command usage:\n" + usageMessage);
return false;
}
private boolean badPerm(CommandSender sender, String perm) {
if (!sender.hasPermission("bukkit.command.whitelist." + perm)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to perform this action.");
return true;
}
return false;
}
@Override
public boolean matches(String input) {
return input.startsWith("whitelist ") || input.equalsIgnoreCase("whitelist");
}
}
|