Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
KickCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.List;
4 
5 import org.apache.commons.lang.Validate;
6 import org.bukkit.Bukkit;
7 import org.bukkit.ChatColor;
10 import org.bukkit.entity.Player;
11 
12 import com.google.common.collect.ImmutableList;
13 
14 public class KickCommand extends VanillaCommand {
15  public KickCommand() {
16  super("kick");
17  this.description = "Removes the specified player from the server";
18  this.usageMessage = "/kick <player> [reason ...]";
19  this.setPermission("bukkit.command.kick");
20  }
21 
22  @Override
23  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
24  if (!testPermission(sender)) return true;
25  if (args.length < 1 || args[0].length() == 0) {
26  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
27  return false;
28  }
29 
30  Player player = Bukkit.getPlayerExact(args[0]);
31 
32  if (player != null) {
33  String reason = "Kicked by an operator.";
34 
35  if (args.length > 1) {
36  reason = createString(args, 1);
37  }
38 
39  player.kickPlayer(reason);
40  Command.broadcastCommandMessage(sender, "Kicked player " + player.getName() + ". With reason:\n" + reason);
41  } else {
42  sender.sendMessage( args[0] + " not found.");
43  }
44 
45  return true;
46  }
47 
48  @Override
49  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
50  Validate.notNull(sender, "Sender cannot be null");
51  Validate.notNull(args, "Arguments cannot be null");
52  Validate.notNull(alias, "Alias cannot be null");
53 
54  if (args.length >= 1) {
55  return super.tabComplete(sender, alias, args);
56  }
57  return ImmutableList.of();
58  }
59 }
boolean testPermission(CommandSender target)
void kickPlayer(String message)
void sendMessage(String message)
void setPermission(String permission)
static Player getPlayerExact(String name)
Definition: Bukkit.java:436