Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cCompositeChat Class Reference

Container for a single chat message composed of multiple functional parts. More...

#include <CompositeChat.h>

Classes

struct  BasePart
 
struct  ClientTranslatedPart
 
struct  CommandPart
 
struct  RunCommandPart
 
struct  ShowAchievementPart
 
struct  SuggestCommandPart
 
struct  TextPart
 
struct  UrlPart
 

Public Member Functions

void AddChatPartStyle (Json::Value &a_Value, const AString &a_PartStyle) const
 Adds the chat part's style (represented by the part's stylestring) into the Json object. More...
 
void AddClientTranslatedPart (const AString &a_TranslationID, const AStringVector &a_Parameters, const AString &a_Style="")
 Adds a part that is translated client-side, with the formatting parameters and optional style. More...
 
void AddRunCommandPart (const AString &a_Text, const AString &a_Command, const AString &a_Style="na")
 Adds a part that runs a command when clicked. More...
 
void AddShowAchievementPart (const AString &a_PlayerName, const AString &a_Achievement, const AString &a_Style="")
 Adds a part that fully formats a specified achievement using client translatable strings Takes achievement name and player awarded to. More...
 
void AddSuggestCommandPart (const AString &a_Text, const AString &a_SuggestedCommand, const AString &a_Style="nb")
 Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked. More...
 
void AddTextPart (const AString &a_Message, const AString &a_Style="")
 Adds a plain text part, with optional style. More...
 
void AddUrlPart (const AString &a_Text, const AString &a_Url, const AString &a_Style="nc")
 Adds a part that opens an URL when clicked. More...
 
 cCompositeChat (const AString &a_ParseText, eMessageType a_MessageType=mtCustom)
 Creates a new chat message and parses the text into parts. More...
 
 cCompositeChat (void)
 Creates a new empty chat message. More...
 
void Clear (void)
 Removes all parts from the object. More...
 
AString CreateJsonString (bool a_ShouldUseChatPrefixes=true) const
 
AString ExtractText (void) const
 Returns the text from the parts that comprises the human-readable data. More...
 
AString GetAdditionalMessageTypeData (void) const
 Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender. More...
 
eMessageType GetMessageType (void) const
 Returns the message type set previously by SetMessageType(). More...
 
const auto & GetParts (void) const
 
void ParseText (const AString &a_ParseText)
 Parses text into various parts, adds those. More...
 
void SetMessageType (eMessageType a_MessageType, const AString &a_AdditionalMessageTypeData="")
 Sets the message type, which is indicated by prefixes added to the message when serializing Takes optional AdditionalMessageTypeData to set m_AdditionalMessageTypeData. More...
 
void UnderlineUrls (void)
 Adds the "underline" style to each part that is an URL. More...
 

Static Public Member Functions

static eLogLevel MessageTypeToLogLevel (eMessageType a_MessageType)
 Converts the MessageType to a LogLevel value. More...
 

Protected Attributes

AString m_AdditionalMessageTypeData
 Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender. More...
 
eMessageType m_MessageType
 The message type, as indicated by prefixes. More...
 
std::vector< std::variant< TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart > > m_Parts
 All the parts that. More...
 

Detailed Description

Container for a single chat message composed of multiple functional parts.

Each part corresponds roughly to the behavior supported by the client messaging:

Definition at line 33 of file CompositeChat.h.

Constructor & Destructor Documentation

◆ cCompositeChat() [1/2]

cCompositeChat::cCompositeChat ( void  )

Creates a new empty chat message.

Exported manually due to the other overload needing a manual export.

Definition at line 18 of file CompositeChat.cpp.

◆ cCompositeChat() [2/2]

cCompositeChat::cCompositeChat ( const AString a_ParseText,
eMessageType  a_MessageType = mtCustom 
)

Creates a new chat message and parses the text into parts.

Recognizes "http:" and "https:" links and &format-character. Uses ParseText() for the actual parsing. Exported manually due to ToLua++ generating extra output parameter.

Definition at line 27 of file CompositeChat.cpp.

Member Function Documentation

◆ AddChatPartStyle()

void cCompositeChat::AddChatPartStyle ( Json::Value &  a_Value,
const AString a_PartStyle 
) const

Adds the chat part's style (represented by the part's stylestring) into the Json object.

Definition at line 381 of file CompositeChat.cpp.

◆ AddClientTranslatedPart()

void cCompositeChat::AddClientTranslatedPart ( const AString a_TranslationID,
const AStringVector a_Parameters,
const AString a_Style = "" 
)

Adds a part that is translated client-side, with the formatting parameters and optional style.

Definition at line 55 of file CompositeChat.cpp.

◆ AddRunCommandPart()

void cCompositeChat::AddRunCommandPart ( const AString a_Text,
const AString a_Command,
const AString a_Style = "na" 
)

Adds a part that runs a command when clicked.

The default style is underlined light green text.

Definition at line 73 of file CompositeChat.cpp.

◆ AddShowAchievementPart()

void cCompositeChat::AddShowAchievementPart ( const AString a_PlayerName,
const AString a_Achievement,
const AString a_Style = "" 
)

Adds a part that fully formats a specified achievement using client translatable strings Takes achievement name and player awarded to.

Displays as {player} has earned the achievement {achievement_name}.

Definition at line 91 of file CompositeChat.cpp.

◆ AddSuggestCommandPart()

void cCompositeChat::AddSuggestCommandPart ( const AString a_Text,
const AString a_SuggestedCommand,
const AString a_Style = "nb" 
)

Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.

The default style is underlined yellow text.

Definition at line 82 of file CompositeChat.cpp.

◆ AddTextPart()

void cCompositeChat::AddTextPart ( const AString a_Message,
const AString a_Style = "" 
)

Adds a plain text part, with optional style.

The default style is plain white text.

Definition at line 46 of file CompositeChat.cpp.

◆ AddUrlPart()

void cCompositeChat::AddUrlPart ( const AString a_Text,
const AString a_Url,
const AString a_Style = "nc" 
)

Adds a part that opens an URL when clicked.

The default style is underlined light blue text.

Definition at line 64 of file CompositeChat.cpp.

◆ Clear()

void cCompositeChat::Clear ( void  )

Removes all parts from the object.

Definition at line 37 of file CompositeChat.cpp.

◆ CreateJsonString()

AString cCompositeChat::CreateJsonString ( bool  a_ShouldUseChatPrefixes = true) const

Definition at line 283 of file CompositeChat.cpp.

◆ ExtractText()

AString cCompositeChat::ExtractText ( void  ) const

Returns the text from the parts that comprises the human-readable data.

Used for older protocols that don't support composite chat and for console-logging.

Definition at line 237 of file CompositeChat.cpp.

◆ GetAdditionalMessageTypeData()

AString cCompositeChat::GetAdditionalMessageTypeData ( void  ) const
inline

Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.

Definition at line 158 of file CompositeChat.h.

◆ GetMessageType()

eMessageType cCompositeChat::GetMessageType ( void  ) const
inline

Returns the message type set previously by SetMessageType().

Definition at line 155 of file CompositeChat.h.

◆ GetParts()

const auto& cCompositeChat::GetParts ( void  ) const
inline

Definition at line 169 of file CompositeChat.h.

◆ MessageTypeToLogLevel()

eLogLevel cCompositeChat::MessageTypeToLogLevel ( eMessageType  a_MessageType)
static

Converts the MessageType to a LogLevel value.

Used by the logging bindings when logging a cCompositeChat object.

Definition at line 259 of file CompositeChat.cpp.

◆ ParseText()

void cCompositeChat::ParseText ( const AString a_ParseText)

Parses text into various parts, adds those.

Parse the input message to add colors or link then add it to the object.

Recognizes "http:" and "https:" URLs and &color-codes.

It detects every & of the message and the next character for it to colorize. It detect : in the text to detect link structures.

Parameters
a_ParseTextThe input text to parse

Definition at line 107 of file CompositeChat.cpp.

◆ SetMessageType()

void cCompositeChat::SetMessageType ( eMessageType  a_MessageType,
const AString a_AdditionalMessageTypeData = "" 
)

Sets the message type, which is indicated by prefixes added to the message when serializing Takes optional AdditionalMessageTypeData to set m_AdditionalMessageTypeData.

See said variable for more documentation. Exported manually, because ToLua++ would generate extra return values.

Definition at line 207 of file CompositeChat.cpp.

◆ UnderlineUrls()

void cCompositeChat::UnderlineUrls ( void  )

Adds the "underline" style to each part that is an URL.

Definition at line 217 of file CompositeChat.cpp.

Member Data Documentation

◆ m_AdditionalMessageTypeData

AString cCompositeChat::m_AdditionalMessageTypeData
protected

Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.

Definition at line 187 of file CompositeChat.h.

◆ m_MessageType

eMessageType cCompositeChat::m_MessageType
protected

The message type, as indicated by prefixes.

Definition at line 184 of file CompositeChat.h.

◆ m_Parts

std::vector<std::variant<TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart> > cCompositeChat::m_Parts
protected

All the parts that.

Definition at line 181 of file CompositeChat.h.


The documentation for this class was generated from the following files: