001 package org.bukkit.command.defaults; 002 003 import java.util.List; 004 005 import org.apache.commons.lang.Validate; 006 import org.bukkit.Bukkit; 007 import org.bukkit.ChatColor; 008 import org.bukkit.command.Command; 009 import org.bukkit.command.CommandSender; 010 import org.bukkit.entity.Player; 011 012 import com.google.common.collect.ImmutableList; 013 014 public class KickCommand extends VanillaCommand { 015 public KickCommand() { 016 super("kick"); 017 this.description = "Removes the specified player from the server"; 018 this.usageMessage = "/kick <player> [reason ...]"; 019 this.setPermission("bukkit.command.kick"); 020 } 021 022 @Override 023 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 024 if (!testPermission(sender)) return true; 025 if (args.length < 1 || args[0].length() == 0) { 026 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 027 return false; 028 } 029 030 Player player = Bukkit.getPlayerExact(args[0]); 031 032 if (player != null) { 033 String reason = "Kicked by an operator."; 034 035 if (args.length > 1) { 036 reason = createString(args, 1); 037 } 038 039 player.kickPlayer(reason); 040 Command.broadcastCommandMessage(sender, "Kicked player " + player.getName() + ". With reason:\n" + reason); 041 } else { 042 sender.sendMessage( args[0] + " not found."); 043 } 044 045 return true; 046 } 047 048 @Override 049 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 050 Validate.notNull(sender, "Sender cannot be null"); 051 Validate.notNull(args, "Arguments cannot be null"); 052 Validate.notNull(alias, "Alias cannot be null"); 053 054 if (args.length >= 1) { 055 return super.tabComplete(sender, alias, args); 056 } 057 return ImmutableList.of(); 058 } 059 }