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.OfflinePlayer; 010 import org.bukkit.command.Command; 011 import org.bukkit.command.CommandSender; 012 import org.bukkit.entity.Player; 013 import org.bukkit.util.StringUtil; 014 015 import com.google.common.collect.ImmutableList; 016 017 public class DeopCommand extends VanillaCommand { 018 public DeopCommand() { 019 super("deop"); 020 this.description = "Takes the specified player's operator status"; 021 this.usageMessage = "/deop <player>"; 022 this.setPermission("bukkit.command.op.take"); 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 || args[0].length() == 0) { 029 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 030 return false; 031 } 032 033 OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); 034 player.setOp(false); 035 036 if (player instanceof Player) { 037 ((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!"); 038 } 039 040 Command.broadcastCommandMessage(sender, "De-opped " + 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 List<String> completions = new ArrayList<String>(); 052 for (OfflinePlayer player : Bukkit.getOperators()) { 053 String playerName = player.getName(); 054 if (StringUtil.startsWithIgnoreCase(playerName, args[0])) { 055 completions.add(playerName); 056 } 057 } 058 return completions; 059 } 060 return ImmutableList.of(); 061 } 062 }