Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PardonCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 import org.apache.commons.lang.Validate;
7 import org.bukkit.BanList;
8 import org.bukkit.Bukkit;
9 import org.bukkit.ChatColor;
10 import org.bukkit.OfflinePlayer;
11 import org.bukkit.command.Command;
13 import org.bukkit.util.StringUtil;
14 
15 import com.google.common.collect.ImmutableList;
16 
17 public class PardonCommand extends VanillaCommand {
18  public PardonCommand() {
19  super("pardon");
20  this.description = "Allows the specified player to use this server";
21  this.usageMessage = "/pardon <player>";
22  this.setPermission("bukkit.command.unban.player");
23  }
24 
25  @Override
26  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
27  if (!testPermission(sender)) return true;
28  if (args.length != 1) {
29  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
30  return false;
31  }
32 
34  Command.broadcastCommandMessage(sender, "Pardoned " + args[0]);
35  return true;
36  }
37 
38  @Override
39  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
40  Validate.notNull(sender, "Sender cannot be null");
41  Validate.notNull(args, "Arguments cannot be null");
42  Validate.notNull(alias, "Alias cannot be null");
43 
44  if (args.length == 1) {
45  List<String> completions = new ArrayList<String>();
46  for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
47  String name = player.getName();
48  if (StringUtil.startsWithIgnoreCase(name, args[0])) {
49  completions.add(name);
50  }
51  }
52  return completions;
53  }
54  return ImmutableList.of();
55  }
56 }
boolean testPermission(CommandSender target)
static Set< OfflinePlayer > getBannedPlayers()
Definition: Bukkit.java:464
void pardon(String target)
void sendMessage(String message)
void setPermission(String permission)
static BanList getBanList(BanList.Type type)
Definition: Bukkit.java:471
static boolean startsWithIgnoreCase(final String string, final String prefix)
Definition: StringUtil.java:50