Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
SayCommand.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 SayCommand extends VanillaCommand {
15  public SayCommand() {
16  super("say");
17  this.description = "Broadcasts the given message as the sender";
18  this.usageMessage = "/say <message ...>";
19  this.setPermission("bukkit.command.say");
20  }
21 
22  @Override
23  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
24  if (!testPermission(sender)) return true;
25  if (args.length == 0) {
26  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
27  return false;
28  }
29 
30  StringBuilder message = new StringBuilder();
31  message.append(ChatColor.LIGHT_PURPLE).append("[");
32  if (sender instanceof ConsoleCommandSender) {
33  message.append("Server");
34  } else if (sender instanceof Player) {
35  message.append(((Player) sender).getDisplayName());
36  } else {
37  message.append(sender.getName());
38  }
39  message.append(ChatColor.LIGHT_PURPLE).append("] ");
40 
41  if (args.length > 0) {
42  message.append(args[0]);
43  for (int i = 1; i < args.length; i++) {
44  message.append(" ").append(args[i]);
45  }
46  }
47 
48  Bukkit.broadcastMessage(message.toString());
49  return true;
50  }
51 
52  @Override
53  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
54  Validate.notNull(sender, "Sender cannot be null");
55  Validate.notNull(args, "Arguments cannot be null");
56 
57  if (args.length >= 1) {
58  return super.tabComplete(sender, alias, args);
59  }
60  return ImmutableList.of();
61  }
62 }
boolean testPermission(CommandSender target)
static int broadcastMessage(String message)
Definition: Bukkit.java:171
void sendMessage(String message)
void setPermission(String permission)