001 package org.bukkit.command.defaults; 002 003 import java.util.List; 004 005 import org.apache.commons.lang.Validate; 006 import org.bukkit.Bukkit; 007 import org.bukkit.ChatColor; 008 import org.bukkit.command.CommandSender; 009 import org.bukkit.command.ConsoleCommandSender; 010 import org.bukkit.entity.Player; 011 012 import com.google.common.collect.ImmutableList; 013 014 public class SayCommand extends VanillaCommand { 015 public SayCommand() { 016 super("say"); 017 this.description = "Broadcasts the given message as the sender"; 018 this.usageMessage = "/say <message ...>"; 019 this.setPermission("bukkit.command.say"); 020 } 021 022 @Override 023 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 024 if (!testPermission(sender)) return true; 025 if (args.length == 0) { 026 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 027 return false; 028 } 029 030 StringBuilder message = new StringBuilder(); 031 message.append(ChatColor.LIGHT_PURPLE).append("["); 032 if (sender instanceof ConsoleCommandSender) { 033 message.append("Server"); 034 } else if (sender instanceof Player) { 035 message.append(((Player) sender).getDisplayName()); 036 } else { 037 message.append(sender.getName()); 038 } 039 message.append(ChatColor.LIGHT_PURPLE).append("] "); 040 041 if (args.length > 0) { 042 message.append(args[0]); 043 for (int i = 1; i < args.length; i++) { 044 message.append(" ").append(args[i]); 045 } 046 } 047 048 Bukkit.broadcastMessage(message.toString()); 049 return true; 050 } 051 052 @Override 053 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 054 Validate.notNull(sender, "Sender cannot be null"); 055 Validate.notNull(args, "Arguments cannot be null"); 056 057 if (args.length >= 1) { 058 return super.tabComplete(sender, alias, args); 059 } 060 return ImmutableList.of(); 061 } 062 }