Update /say to vanilla behaviour. Fixes BUKKIT-4224

Prior to this commit all /say command output would be a generic "[Server]"
prefixed line. This commit changes that by adding the source into the
message, such as a player. By doing this Bukkit more closely matches
vanilla behaviour and gives a more descriptive message to the client.

By: Kezz101 <1millionchances@gmail.com>
This commit is contained in:
Bukkit/Spigot 2013-07-03 13:40:06 +01:00
parent d89e4c7927
commit 5462a33b20

View file

@ -6,6 +6,7 @@ import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -14,7 +15,7 @@ public class SayCommand extends VanillaCommand {
public SayCommand() { public SayCommand() {
super("say"); super("say");
this.description = "Broadcasts the given message as the console"; this.description = "Broadcasts the given message as the console";
this.usageMessage = "/say <message>"; this.usageMessage = "/say <message ...>";
this.setPermission("bukkit.command.say"); this.setPermission("bukkit.command.say");
} }
@ -27,20 +28,24 @@ public class SayCommand extends VanillaCommand {
} }
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.append(ChatColor.LIGHT_PURPLE).append("[");
if (sender instanceof ConsoleCommandSender) {
message.append("Server");
} else if (sender instanceof Player) {
message.append(((Player) sender).getDisplayName());
} else {
message.append(sender.getName());
}
message.append(ChatColor.LIGHT_PURPLE).append("] ");
if (args.length > 0) { if (args.length > 0) {
message.append(args[0]); message.append(args[0]);
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
message.append(" "); message.append(" ").append(args[i]);
message.append(args[i]);
} }
} }
if (sender instanceof Player) { Bukkit.broadcastMessage(message.toString());
Bukkit.getLogger().info("[" + sender.getName() + "] " + message);
}
Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[Server] " + message);
return true; return true;
} }