001 package org.bukkit.command.defaults; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import org.apache.commons.lang.Validate; 007 import org.bukkit.Bukkit; 008 import org.bukkit.ChatColor; 009 import org.bukkit.command.Command; 010 import org.bukkit.command.CommandSender; 011 import org.bukkit.util.StringUtil; 012 013 import com.google.common.collect.ImmutableList; 014 015 public class PardonIpCommand extends VanillaCommand { 016 public PardonIpCommand() { 017 super("pardon-ip"); 018 this.description = "Allows the specified IP address to use this server"; 019 this.usageMessage = "/pardon-ip <address>"; 020 this.setPermission("bukkit.command.unban.ip"); 021 } 022 023 @Override 024 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 025 if (!testPermission(sender)) return true; 026 if (args.length != 1) { 027 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 028 return false; 029 } 030 031 if (BanIpCommand.ipValidity.matcher(args[0]).matches()) { 032 Bukkit.unbanIP(args[0]); 033 Command.broadcastCommandMessage(sender, "Pardoned ip " + args[0]); 034 } else { 035 sender.sendMessage("Invalid ip"); 036 } 037 038 return true; 039 } 040 041 @Override 042 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 043 Validate.notNull(sender, "Sender cannot be null"); 044 Validate.notNull(args, "Arguments cannot be null"); 045 Validate.notNull(alias, "Alias cannot be null"); 046 047 if (args.length == 1) { 048 return StringUtil.copyPartialMatches(args[0], Bukkit.getIPBans(), new ArrayList<String>()); 049 } 050 return ImmutableList.of(); 051 } 052 }