Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
DeopCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 import org.apache.commons.lang.Validate;
7 import org.bukkit.Bukkit;
8 import org.bukkit.ChatColor;
10 import org.bukkit.command.Command;
12 import org.bukkit.entity.Player;
13 import org.bukkit.util.StringUtil;
14 
15 import com.google.common.collect.ImmutableList;
16 
17 public class DeopCommand extends VanillaCommand {
18  public DeopCommand() {
19  super("deop");
20  this.description = "Takes the specified player's operator status";
21  this.usageMessage = "/deop <player>";
22  this.setPermission("bukkit.command.op.take");
23  }
24 
25  @Override
26  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
27  if (!testPermission(sender)) return true;
28  if (args.length != 1 || args[0].length() == 0) {
29  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
30  return false;
31  }
32 
33  OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
34  player.setOp(false);
35 
36  if (player instanceof Player) {
37  ((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
38  }
39 
40  Command.broadcastCommandMessage(sender, "De-opped " + args[0]);
41  return true;
42  }
43 
44  @Override
45  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
46  Validate.notNull(sender, "Sender cannot be null");
47  Validate.notNull(args, "Arguments cannot be null");
48  Validate.notNull(alias, "Alias cannot be null");
49 
50  if (args.length == 1) {
51  List<String> completions = new ArrayList<String>();
52  for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
53  String playerName = player.getName();
54  if (player.isOp() && StringUtil.startsWithIgnoreCase(playerName, args[0])) {
55  completions.add(playerName);
56  }
57  }
58  return completions;
59  }
60  return ImmutableList.of();
61  }
62 }
boolean testPermission(CommandSender target)
void sendMessage(String message)
void setPermission(String permission)
static OfflinePlayer[] getOfflinePlayers()
Definition: Bukkit.java:583
static boolean startsWithIgnoreCase(final String string, final String prefix)
Definition: StringUtil.java:50
static OfflinePlayer getOfflinePlayer(String name)
Definition: Bukkit.java:421