cCompositeChat


Index:
Articles
Classes
Hooks

Quick navigation:
cArrowEntity
cBeaconEntity
cBlockArea
cBlockEntity
cBlockEntityWithItems
cBlockInfo
cBoundingBox
cBrewingstandEntity
cChatColor
cChestEntity
cChunkDesc
cClientHandle
cCommandBlockEntity
cCompositeChat
cCraftingGrid
cCraftingRecipe
cCryptoHash
cCuboid
cDispenserEntity
cDropperEntity
cDropSpenserEntity
cEnchantments
cEntity
cEntityEffect
cExpBottleEntity
cFile
cFireChargeEntity
cFireworkEntity
cFloater
cFlowerPotEntity
cFurnaceEntity
cGhastFireballEntity
cHangingEntity
cHopperEntity
cIniFile
cInventory
cItem
cItemFrame
cItemGrid
cItems
cJson
cJukeboxEntity
cLineBlockTracer
cLuaWindow
cMap
cMapManager
cMobHeadEntity
cMobSpawnerEntity
cMojangAPI
cMonster
cNetwork
cNoteEntity
cObjective
cPainting
cPawn
cPickup
cPlayer
cPlugin
cPluginLua
cPluginManager
cProjectileEntity
cRankManager
cRoot
cScoreboard
cServer
cServerHandle
cSignEntity
cSplashPotionEntity
cStatManager
cStringCompression
cTCPLink
cTeam
cThrownEggEntity
cThrownEnderPearlEntity
cThrownSnowballEntity
cTNTEntity
cTracer
cUDPEndpoint
cUrlClient
cUrlParser
cWebAdmin
cWindow
cWitherSkullEntity
cWorld
HTTPFormData
HTTPRequest
HTTPTemplateRequest
ItemCategory
lxp
sqlite3
TakeDamageInfo
tolua
Vector3d
Vector3f
Vector3i
Globals

Contents


cCompositeChat class

Encapsulates a chat message that can contain various formatting, URLs, commands executed on click and commands suggested on click. The chat message can be sent by the regular chat-sending functions, cPlayer:SendMessage(), cWorld:BroadcastChat() and cRoot:BroadcastChat().

Note that most of the functions in this class are so-called chaining modifiers - they modify the object and then return the object itself, so that they can be chained one after another. See the Chaining example below for details.

Each part of the composite chat message takes a "Style" parameter, this is a string that describes the formatting. It uses the following strings, concatenated together:

StringStyle
bBold text
iItalic text
uUnderlined text
sStrikethrough text
oObfuscated text
@Xcolor X (X is 0 - 9 or a - f, same as dye meta
The following picture, taken from MineCraft Wiki, illustrates the color codes:


Functions

NameParametersReturn valueNotes
() (constructor) Creates an empty chat message
() (constructor) Text, [MessageType] Creates a chat message containing the specified text, parsed by the ParseText() function. This allows easy migration from old chat messages.
AddRunCommandPart Text, Command, [Style] self Adds a text which, when clicked, runs the specified command. Chaining.
AddShowAchievementPart PlayerName, AchievementName, [Style] Adds a text that represents the 'Achievement get' message.
AddSuggestCommandPart Text, Command, [Style] self Adds a text which, when clicked, puts the specified command into the player's chat input area. Chaining.
AddTextPart Text, [Style] self Adds a regular text. Chaining.
AddUrlPart Text, Url, [Style] self Adds a text which, when clicked, opens up a browser at the specified URL. Chaining.
Clear Removes all parts from this object
CreateJsonString [AddPrefixes] string Returns the entire object serialized into JSON, as it would be sent to a client. AddPrefixes specifies whether the chat prefixes should be prepended to the message, true by default.
ExtractText string 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.
GetAdditionalMessageTypeData string Returns the AdditionalData associated with the message, such as the sender's name for mtPrivateMessage
GetMessageType MessageType Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding "[INFO]" prefix etc.)
ParseText Text self Adds text, while recognizing http and https URLs and old-style formatting codes ("@2"). Chaining.
SetMessageType MessageType, [AdditionalData] self Sets the MessageType (mtXXX constant) that is associated with this message. Also sets the additional data (string) associated with the message, which is specific for the message type - such as the sender's name for mtPrivateMessage. When sent to a player, the message will be formatted according to this message type and the player's settings (adding "[INFO]" prefix etc.). Chaining.
UnderlineUrls self Makes all URL parts contained in the message underlined. Doesn't affect parts added in the future. Chaining.

Chaining example

Sending a chat message that is composed of multiple different parts has been made easy thanks to chaining. Consider the following example that shows how a message containing all kinds of parts is sent (adapted from the Debuggers plugin):
function OnPlayerJoined(a_Player)
	-- Send an example composite chat message to the player:
	a_Player:SendMessage(cCompositeChat()
		:AddTextPart("Hello, ")
		:AddUrlPart(a_Player:GetName(), "http://cuberite.org", "u@2")  -- Colored underlined link
		:AddSuggestCommandPart(", and welcome.", "/help", "u")       -- Underlined suggest-command
		:AddRunCommandPart(" SetDay", "/time set 0")                 -- Regular text that will execute command when clicked
		:SetMessageType(mtJoin)                                      -- It is a join-message
	)
end
Generated on 2016-08-22 23:53:06, Build ID Unknown, Commit approx: 2ed4af74edd14ae17e1c6c64d44caa7b7fc30d5a