Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
TellCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.Arrays;
4 
5 import org.bukkit.Bukkit;
6 import org.bukkit.ChatColor;
8 import org.bukkit.entity.Player;
9 
10 public class TellCommand extends VanillaCommand {
11  public TellCommand() {
12  super("tell");
13  this.description = "Sends a private message to the given player";
14  this.usageMessage = "/tell <player> <message>";
15  this.setAliases(Arrays.asList(new String[] { "w", "msg" }));
16  this.setPermission("bukkit.command.tell");
17  }
18 
19  @Override
20  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
21  if (!testPermission(sender)) return true;
22  if (args.length < 2) {
23  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
24  return false;
25  }
26 
27  Player player = Bukkit.getPlayerExact(args[0]);
28 
29  // If a player is hidden from the sender pretend they are offline
30  if (player == null || (sender instanceof Player && !((Player) sender).canSee(player))) {
31  sender.sendMessage("There's no player by that name online.");
32  } else {
33  StringBuilder message = new StringBuilder();
34 
35  for (int i = 1; i < args.length; i++) {
36  if (i > 1) message.append(" ");
37  message.append(args[i]);
38  }
39 
40  String result = ChatColor.GRAY + sender.getName() + " whispers " + message;
41 
42  sender.sendMessage("[" + sender.getName() + "->" + player.getName() + "] " + message);
43  player.sendMessage(result);
44  }
45 
46  return true;
47  }
48 }
boolean testPermission(CommandSender target)
Command setAliases(List< String > aliases)
void sendMessage(String message)
void setPermission(String permission)
static Player getPlayerExact(String name)
Definition: Bukkit.java:436