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.BanList; 008 import org.bukkit.Bukkit; 009 import org.bukkit.ChatColor; 010 import org.bukkit.OfflinePlayer; 011 import org.bukkit.command.Command; 012 import org.bukkit.command.CommandSender; 013 import org.bukkit.util.StringUtil; 014 015 import com.google.common.collect.ImmutableList; 016 017 public class PardonCommand extends VanillaCommand { 018 public PardonCommand() { 019 super("pardon"); 020 this.description = "Allows the specified player to use this server"; 021 this.usageMessage = "/pardon <player>"; 022 this.setPermission("bukkit.command.unban.player"); 023 } 024 025 @Override 026 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 027 if (!testPermission(sender)) return true; 028 if (args.length != 1) { 029 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 030 return false; 031 } 032 033 Bukkit.getBanList(BanList.Type.NAME).pardon(args[0]); 034 Command.broadcastCommandMessage(sender, "Pardoned " + args[0]); 035 return true; 036 } 037 038 @Override 039 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 040 Validate.notNull(sender, "Sender cannot be null"); 041 Validate.notNull(args, "Arguments cannot be null"); 042 Validate.notNull(alias, "Alias cannot be null"); 043 044 if (args.length == 1) { 045 List<String> completions = new ArrayList<String>(); 046 for (OfflinePlayer player : Bukkit.getBannedPlayers()) { 047 String name = player.getName(); 048 if (StringUtil.startsWithIgnoreCase(name, args[0])) { 049 completions.add(name); 050 } 051 } 052 return completions; 053 } 054 return ImmutableList.of(); 055 } 056 }