001 package org.bukkit.command.defaults; 002 003 import java.util.Arrays; 004 005 import org.bukkit.Bukkit; 006 import org.bukkit.ChatColor; 007 import org.bukkit.command.CommandSender; 008 import org.bukkit.entity.Player; 009 010 public class TellCommand extends VanillaCommand { 011 public TellCommand() { 012 super("tell"); 013 this.description = "Sends a private message to the given player"; 014 this.usageMessage = "/tell <player> <message>"; 015 this.setAliases(Arrays.asList(new String[] { "w", "msg" })); 016 this.setPermission("bukkit.command.tell"); 017 } 018 019 @Override 020 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 021 if (!testPermission(sender)) return true; 022 if (args.length < 2) { 023 sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); 024 return false; 025 } 026 027 Player player = Bukkit.getPlayerExact(args[0]); 028 029 // If a player is hidden from the sender pretend they are offline 030 if (player == null || (sender instanceof Player && !((Player) sender).canSee(player))) { 031 sender.sendMessage("There's no player by that name online."); 032 } else { 033 StringBuilder message = new StringBuilder(); 034 035 for (int i = 1; i < args.length; i++) { 036 if (i > 1) message.append(" "); 037 message.append(args[i]); 038 } 039 040 String result = ChatColor.GRAY + sender.getName() + " whispers " + message; 041 042 sender.sendMessage("[" + sender.getName() + "->" + player.getName() + "] " + message); 043 player.sendMessage(result); 044 } 045 046 return true; 047 } 048 }