Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BanCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.List;
4 
5 import org.apache.commons.lang.StringUtils;
6 import org.apache.commons.lang.Validate;
7 import org.bukkit.BanList;
8 import org.bukkit.Bukkit;
9 import org.bukkit.ChatColor;
10 import org.bukkit.command.Command;
12 import org.bukkit.entity.Player;
13 
14 import com.google.common.collect.ImmutableList;
15 
16 public class BanCommand extends VanillaCommand {
17  public BanCommand() {
18  super("ban");
19  this.description = "Prevents the specified player from using this server";
20  this.usageMessage = "/ban <player> [reason ...]";
21  this.setPermission("bukkit.command.ban.player");
22  }
23 
24  @Override
25  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
26  if (!testPermission(sender)) return true;
27  if (args.length == 0) {
28  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
29  return false;
30  }
31 
32  String reason = args.length > 0 ? StringUtils.join(args, ' ', 1, args.length) : null;
33  Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], reason, null, sender.getName());
34 
35  Player player = Bukkit.getPlayer(args[0]);
36  if (player != null) {
37  player.kickPlayer("Banned by admin.");
38  }
39 
40  Command.broadcastCommandMessage(sender, "Banned player " + 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  return super.tabComplete(sender, alias, args);
52  }
53  return ImmutableList.of();
54  }
55 }
boolean testPermission(CommandSender target)
void kickPlayer(String message)
void sendMessage(String message)
void setPermission(String permission)
static BanList getBanList(BanList.Type type)
Definition: Bukkit.java:471
BanEntry addBan(String target, String reason, Date expires, String source)
static Player getPlayer(String name)
Definition: Bukkit.java:186