diff --git a/legacyver/legacypacket/command_output.go b/legacyver/legacypacket/command_output.go index fdf30bf..6e78e7a 100644 --- a/legacyver/legacypacket/command_output.go +++ b/legacyver/legacypacket/command_output.go @@ -26,7 +26,7 @@ type CommandOutput struct { SuccessCount uint32 // OutputMessages is a list of all output messages that should be sent to the player. Whether they are // shown or not, depends on the type of the messages. - OutputMessages []protocol.CommandOutputMessage + OutputMessages []proto.CommandOutputMessage // DataSet ... TODO: Find out what this is for. DataSet protocol.Optional[string] } diff --git a/legacyver/proto/command.go b/legacyver/proto/command.go index 9eb9439..274867c 100644 --- a/legacyver/proto/command.go +++ b/legacyver/proto/command.go @@ -264,3 +264,34 @@ func CommandOriginData(r protocol.IO, x *protocol.CommandOrigin) { r.Varint64(&x.PlayerUniqueID) } } + +// CommandOutputMessage represents a message sent by a command that holds the output of one of the commands +// executed. +type CommandOutputMessage struct { + // Success indicates if the output message was one of a successful command execution. If set to true, the + // output message is by default coloured white, whereas if set to false, the message is by default + // coloured red. + Success bool + // Message is the message that is sent to the client in the chat window. It may either be simply a + // message or a translated built-in string like 'commands.tp.success.coordinates', combined with specific + // parameters below. + Message string + // Parameters is a list of parameters that serve to supply the message sent with additional information, + // such as the position that a player was teleported to or the effect that was applied to an entity. + // These parameters only apply for the Minecraft built-in command output. + Parameters []string +} + +// Marshal encodes/decodes a CommandOutputMessage. +func (x *CommandOutputMessage) Marshal(r protocol.IO) { + if IsProtoLT(r, ID898) { + r.Bool(&x.Success) + } + r.String(&x.Message) + if IsProtoGTE(r, ID898) { + r.Bool(&x.Success) + } + + r.Bool(&x.Success) + protocol.FuncSlice(r, &x.Parameters, r.String) +}