cCompositeChat


Index:
Articles
Classes
Hooks

Quick navigation:
BannerPattern
BossBarColor
BossBarDivisionType
cArrowEntity
cBeaconEntity
cBedEntity
cBlockArea
cBlockEntity
cBlockEntityWithItems
cBlockInfo
cBoat
cBoundingBox
cBrewingstandEntity
cChatColor
cChestEntity
cChunkDesc
cClientHandle
cColor
cCommandBlockEntity
cCompositeChat
cCraftingGrid
cCraftingRecipe
cCryptoHash
cCuboid
cDispenserEntity
cDropperEntity
cDropSpenserEntity
cEnchantments
cEnderCrystal
cEntity
cEntityEffect
cExpBottleEntity
cExpOrb
cFallingBlock
cFile
cFireChargeEntity
cFireworkEntity
cFloater
cFlowerPotEntity
cFurnaceEntity
cGhastFireballEntity
cHangingEntity
cHopperEntity
cIniFile
cInventory
cItem
cItemFrame
cItemGrid
cItems
cJson
cJukeboxEntity
cLeashKnot
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
cStringCompression
cTCPLink
cTeam
cThrownEggEntity
cThrownEnderPearlEntity
cThrownSnowballEntity
cTNTEntity
cUDPEndpoint
cUrlClient
cUrlParser
CustomStatistic
cUUID
cWebAdmin
cWindow
cWitherSkullEntity
cWorld
EffectID
HTTPFormData
HTTPRequest
HTTPTemplateRequest
ItemCategory
lxp
SmokeDirection
sqlite3
StatisticsManager
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 "standard" minecraft format code without the '&' symbole, concatenated together:

StringStyle
lBold text
oItalic text
nUnderlined text
mStrikethrough text
kObfuscated text
rReset Style
[0-9a-f]colors
You can escape the '&' character with an antislash in front of it. as follow: `I love Choco\&chips` The following picture, taken from the Minecraft Wiki, illustrates the color codes:


Functions

NameParametersReturn valueNotes
() (constructor)
Textstring
MessageTypeeMessageType
cCompositeChat
Creates a chat message containing the specified text, parsed by the ParseText() function. This allows easy migration from old chat messages.
() (constructor)
cCompositeChat
Creates an empty chat message
AddRunCommandPart
Textstring
Commandstring
Stylestring
self
Adds a text which, when clicked, runs the specified command. Chaining.
AddShowAchievementPart
PlayerNamestring
AchievementNamestring
Stylestring
Adds a text that represents the 'Achievement get' message.
AddSuggestCommandPart
Textstring
Commandstring
Stylestring
self
Adds a text which, when clicked, puts the specified command into the player's chat input area. Chaining.
AddTextPart
Textstring
Stylestring
self
Adds a regular text. Chaining.
AddUrlPart
Textstring
Urlstring
Stylestring
self
Adds a text which, when clicked, opens up a browser at the specified URL. Chaining.
Clear
self
Removes all parts from this object
CreateJsonString
AddPrefixesboolean
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
eMessageType
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
Textstring
self
Adds text, while recognizing http and https URLs and old-style formatting codes ("@2"). Chaining.
SetMessageType
MessageTypeeMessageType
AdditionalDatastring
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(), "https://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 by APIDump on 2024-10-25 05:01:00, Build ID Unknown, Commit approx: 0325de7dacaf1e2feaea5eaab4791bc23d78f9e7