001 package org.bukkit.command.defaults; 002 003 import java.util.List; 004 005 import org.apache.commons.lang.StringUtils; 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.command.Command; 011 import org.bukkit.command.CommandSender; 012 import org.bukkit.entity.Player; 013 014 import com.google.common.collect.ImmutableList; 015 016 public class BanCommand extends VanillaCommand { 017 public BanCommand() { 018 super("ban"); 019 this.description = "Prevents the specified player from using this server"; 020 this.usageMessage = "/ban <player> [reason ...]"; 021 this.setPermission("bukkit.command.ban.player"); 022 } 023 024 @Override 025 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 026 if (!testPermission(sender)) return true; 027 if (args.length == 0) { 028 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 029 return false; 030 } 031 032 String reason = args.length > 0 ? StringUtils.join(args, ' ', 1, args.length) : null; 033 Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], reason, null, sender.getName()); 034 035 Player player = Bukkit.getPlayer(args[0]); 036 if (player != null) { 037 player.kickPlayer("Banned by admin."); 038 } 039 040 Command.broadcastCommandMessage(sender, "Banned player " + args[0]); 041 return true; 042 } 043 044 @Override 045 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 046 Validate.notNull(sender, "Sender cannot be null"); 047 Validate.notNull(args, "Arguments cannot be null"); 048 Validate.notNull(alias, "Alias cannot be null"); 049 050 if (args.length >= 1) { 051 return super.tabComplete(sender, alias, args); 052 } 053 return ImmutableList.of(); 054 } 055 }