Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PardonIpCommand.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.Bukkit;
8 import org.bukkit.ChatColor;
11 import org.bukkit.util.StringUtil;
12 
13 import com.google.common.collect.ImmutableList;
14 
15 public class PardonIpCommand extends VanillaCommand {
16  public PardonIpCommand() {
17  super("pardon-ip");
18  this.description = "Allows the specified IP address to use this server";
19  this.usageMessage = "/pardon-ip <address>";
20  this.setPermission("bukkit.command.unban.ip");
21  }
22 
23  @Override
24  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
25  if (!testPermission(sender)) return true;
26  if (args.length != 1) {
27  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
28  return false;
29  }
30 
31  if (BanIpCommand.ipValidity.matcher(args[0]).matches()) {
32  Bukkit.unbanIP(args[0]);
33  Command.broadcastCommandMessage(sender, "Pardoned ip " + args[0]);
34  } else {
35  sender.sendMessage("Invalid ip");
36  }
37 
38  return true;
39  }
40 
41  @Override
42  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
43  Validate.notNull(sender, "Sender cannot be null");
44  Validate.notNull(args, "Arguments cannot be null");
45  Validate.notNull(alias, "Alias cannot be null");
46 
47  if (args.length == 1) {
48  return StringUtil.copyPartialMatches(args[0], Bukkit.getIPBans(), new ArrayList<String>());
49  }
50  return ImmutableList.of();
51  }
52 }
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 Set< String > getIPBans()
Definition: Bukkit.java:443
static void unbanIP(String address)
Definition: Bukkit.java:457