The bug
If you run a command from chat multiple consecutive spaces will be collapsed to a single space.
Reproductions steps
Execute the following command in chat
/tellraw @s "1 2"
❌ Only one space is shown between the two numbers
Code analysis
The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.
The reason why this is happening is because the method net.minecraft.network.NetHandlerPlayServer.processChatMessage(CPacketChatMessage)
removes multiple whitespaces before testing if the entered message is a command or not. The test whether or not the message contains the section character §
is probably not needed for commands neither.
/**
* Process chat messages (broadcast back to clients) and commands (executes)
*/
public void processChatMessage(CPacketChatMessage packetIn)
{
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
{
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
textcomponenttranslation.getChatStyle().setColor(TextFormatting.RED);
this.sendPacket(new SPacketChat(textcomponenttranslation));
}
else
{
this.playerEntity.markPlayerActive();
String s = packetIn.getMessage();
// Removed this from here
//s = StringUtils.normalizeSpace(s);
//
//for (int i = 0; i < s.length(); ++i)
//{
// if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
// {
// this.kickPlayerFromServer("Illegal characters in chat");
// return;
// }
//}
if (s.startsWith("/"))
{
this.handleSlashCommand(s);
}
else
{
// Added this here
s = StringUtils.normalizeSpace(s);
for (int i = 0; i < s.length(); ++i)
{
if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
{
this.kickPlayerFromServer("Illegal characters in chat");
return;
}
}
ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
}
this.chatSpamThresholdCount += 20;
if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
{
this.kickPlayerFromServer("disconnect.spam");
}
}
}
Linked issues
is duplicated by 8
relates to 2
Attachments
Comments 35
Confirmed for:
1.8.2-pre1
Please change the title to: Chat, signs and tellraw trim text and remove multiple spaces
This is definitely not intended for tellraw and signs because there is no way for players to spam the chat
Manually placed signs don't trim whitespace, but it appears that commands do. Probably has to do with how the text is parsed.
Title is wrong, only commands send via chat are affected; using tellraw via command block does not trim spaces.
Is this still a concern in the current Minecraft version? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases. If this has been done, we can reopen the issue.
Keep in mind that the "Resolved"-Status on this ticket just means "Answered", and that we are waiting for further information on whether this issue still exists or not. We will reopen it as soon as the requested information has been delivered.