Skip to content

Commit

Permalink
Update /say to vanilla behaviour. Fixes BUKKIT-4224
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kezz101 authored and turt2live committed Sep 11, 2013
1 parent 22a61ef commit eaf0265
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/org/bukkit/command/defaults/SayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

import com.google.common.collect.ImmutableList;
Expand All @@ -14,7 +15,7 @@ public class SayCommand extends VanillaCommand {
public SayCommand() {
super("say");
this.description = "Broadcasts the given message as the console";
this.usageMessage = "/say <message>";
this.usageMessage = "/say <message ...>";
this.setPermission("bukkit.command.say");
}

Expand All @@ -27,20 +28,24 @@ public boolean execute(CommandSender sender, String currentAlias, String[] args)
}

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) {
message.append(args[0]);
for (int i = 1; i < args.length; i++) {
message.append(" ");
message.append(args[i]);
message.append(" ").append(args[i]);
}
}

if (sender instanceof Player) {
Bukkit.getLogger().info("[" + sender.getName() + "] " + message);
}

Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[Server] " + message);

Bukkit.broadcastMessage(message.toString());
return true;
}

Expand Down

0 comments on commit eaf0265

Please sign in to comment.