Phpcraft
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Phpcraft\ChatComponent Class Reference

Public Member Functions

 toString (int $format=ChatComponent::FORMAT_NONE)
 
 toArray (bool $explicit=false)
 
 add ($chat)
 
 insertion (string $insertion)
 
 onClickOpenLink (string $url)
 
 onClickSendMessage (string $message)
 
 onClickSuggestMessage (string $message)
 
 onClickChangePage (int $page)
 
 black ()
 
 dark_blue ()
 
 dark_green ()
 
 dark_aqua ()
 
 dark_red ()
 
 dark_purple ()
 
 gold ()
 
 gray ()
 
 dark_gray ()
 
 blue ()
 
 green ()
 
 aqua ()
 
 red ()
 
 light_purple ()
 
 yellow ()
 
 white ()
 
 bold ()
 
 strikethrough ()
 
 underline ()
 
 italic ()
 
 obfuscate ()
 

Static Public Member Functions

static downloadTranslations (string $language_code="en_GB")
 
static container (ChatComponent... $children)
 
static text (string $text, bool $allow_amp=false)
 
static translate (string $key, array $with=[])
 
static cast ($value)
 
static fromArray (array $array)
 
static keybind (string $name)
 

Public Attributes

const FORMAT_NONE = 0
 
const FORMAT_ANSI = 1
 
const FORMAT_SILCROW = 2
 
const FORMAT_AMPERSAND = 3
 
const FORMAT_HTML = 4
 
 $text
 
 $color = null
 
 $bold = false
 
 $italic = false
 
 $underlined = false
 
 $strikethrough = false
 
 $obfuscated = false
 
 $extra = []
 
 $translate = null
 
 $with = []
 
 $keybind = null
 
 $insertion = null
 
 $click_event = null
 

Static Public Attributes

static $translations
 
static $hex_to_color
 
static $color_to_hex
 
static $color_to_ansi
 
static $color_to_rgb_hex
 
static $attributes
 
static $attributes_legacy
 
static $attributes_ansi
 
static $attributes_html
 

Detailed Description

Since
0.4

Member Function Documentation

◆ add()

Phpcraft\ChatComponent::add (   $chat)

Casts $chat to a ChatComponent and adds it to $this->extra.

Parameters
array | string | null | ChatComponent$chat
Returns
ChatComponent $this

◆ aqua()

Phpcraft\ChatComponent::aqua ( )

Sets $this->color to "aqua".

Returns
ChatComponent $this

◆ black()

Phpcraft\ChatComponent::black ( )

Sets $this->color to "black".

Returns
ChatComponent $this

◆ blue()

Phpcraft\ChatComponent::blue ( )

Sets $this->color to "blue".

Returns
ChatComponent $this

◆ bold()

Phpcraft\ChatComponent::bold ( )

Sets $this->bold to true.

Returns
ChatComponent $this

◆ cast()

static Phpcraft\ChatComponent::cast (   $value)
static

Casts the given value into a ChatComponent.

Parameters
array | string | null | ChatComponent$value
Returns
ChatComponent

◆ container()

static Phpcraft\ChatComponent::container ( ChatComponent...  $children)
static

Instantiates a blank ChatComponent that only serves to contain other ChatComponent instances.

Parameters
$childrenChatComponent[]
Returns
ChatComponent
Since
0.4.1

◆ dark_aqua()

Phpcraft\ChatComponent::dark_aqua ( )

Sets $this->color to "dark_aqua".

Returns
ChatComponent $this

◆ dark_blue()

Phpcraft\ChatComponent::dark_blue ( )

Sets $this->color to "dark_blue".

Returns
ChatComponent $this

◆ dark_gray()

Phpcraft\ChatComponent::dark_gray ( )

Sets $this->color to "dark_gray".

Returns
ChatComponent $this

◆ dark_green()

Phpcraft\ChatComponent::dark_green ( )

Sets $this->color to "dark_green".

Returns
ChatComponent $this

◆ dark_purple()

Phpcraft\ChatComponent::dark_purple ( )

Sets $this->color to "dark_purple".

Returns
ChatComponent $this

◆ dark_red()

Phpcraft\ChatComponent::dark_red ( )

Sets $this->color to "dark_red".

Returns
ChatComponent $this

◆ downloadTranslations()

static Phpcraft\ChatComponent::downloadTranslations ( string  $language_code = "en_GB")
static

Downloads the latest supported Minecraft version's translation for the given language into ChatComponent::$translations, so messages using a "translate" component will be displayed correctly. Note that we can't use en_US because that is compiled into Minecraft's jar and not (legally) accessible otherwise.

Parameters
string$language_code
Returns
bool True if the translations for the given language have been applied.

◆ fromArray()

static Phpcraft\ChatComponent::fromArray ( array  $array)
static

◆ gold()

Phpcraft\ChatComponent::gold ( )

Sets $this->color to "gold".

Returns
ChatComponent $this

◆ gray()

Phpcraft\ChatComponent::gray ( )

Sets $this->color to "gray".

Returns
ChatComponent $this

◆ green()

Phpcraft\ChatComponent::green ( )

Sets $this->color to "green".

Returns
ChatComponent $this

◆ insertion()

Phpcraft\ChatComponent::insertion ( string  $insertion)

Sets text to be inserted into the client's chat box when they shift-click the ChatComponent.

Parameters
string$insertion
Returns
ChatComponent $this

◆ italic()

Phpcraft\ChatComponent::italic ( )

Sets $this->italic to true.

Returns
ChatComponent $this

◆ keybind()

static Phpcraft\ChatComponent::keybind ( string  $name)
static

Initiates a "keybind" ChatComponent.

Parameters
string$nameThe name of the key, named after the value in the options.txt, e.g. "key_key.forward" in options.txt would mean "key.forward" here, and "w" would be displayed.
Returns
ChatComponent
Since
0.4.1

◆ light_purple()

Phpcraft\ChatComponent::light_purple ( )

Sets $this->color to "light_purple".

Returns
ChatComponent $this

◆ obfuscate()

Phpcraft\ChatComponent::obfuscate ( )

Sets $this->obfuscated to true.

Returns
ChatComponent $this

◆ onClickChangePage()

Phpcraft\ChatComponent::onClickChangePage ( int  $page)

When the client clicks on the ChatComponent, the given page in the book will be opened, where 1 is the first page. Only usable in books. A ChatComponent can only have one click event.

Parameters
int$page
Returns
ChatComponent $this

◆ onClickOpenLink()

Phpcraft\ChatComponent::onClickOpenLink ( string  $url)

When the client clicks on the ChatComponent, the given URL will be opened. A ChatComponent can only have one click event.

Parameters
string$urlProtocol must be "http" or "https"
Returns
ChatComponent $this

◆ onClickSendMessage()

Phpcraft\ChatComponent::onClickSendMessage ( string  $message)

When the client clicks on the ChatComponent, the given message will be sent in chat. A ChatComponent can only have one click event.

Parameters
string$message
Returns
ChatComponent $this

◆ onClickSuggestMessage()

Phpcraft\ChatComponent::onClickSuggestMessage ( string  $message)

When the client clicks on the ChatComponent, the given message will be put into their chat box. Only usable in chat messages. A ChatComponent can only have one click event.

Parameters
string$message
Returns
ChatComponent $this

◆ red()

Phpcraft\ChatComponent::red ( )

Sets $this->color to "red".

Returns
ChatComponent $this

◆ strikethrough()

Phpcraft\ChatComponent::strikethrough ( )

Sets $this->strikethrough to true.

Returns
ChatComponent $this

◆ text()

static Phpcraft\ChatComponent::text ( string  $text,
bool  $allow_amp = false 
)
static

Instantiates a ChatComponent with the given text. If the text has § format codes, they will be applied to the ChatComponent.

Parameters
string$text
bool$allow_ampIf true, '&' will be handled like '§'.
Returns
ChatComponent

◆ toArray()

Phpcraft\ChatComponent::toArray ( bool  $explicit = false)
Parameters
bool$explicitExplicitly set every property, even if its value can be implied.
Returns
array

◆ toString()

Phpcraft\ChatComponent::toString ( int  $format = ChatComponent::FORMAT_NONE)

Converts the ChatComponent to a string.

Parameters
int$formatThe format to apply. Note that HTML format will provide a non-standard "obfuscated" tag, should any text require it.
Returns
string

◆ translate()

static Phpcraft\ChatComponent::translate ( string  $key,
array  $with = [] 
)
static

Instantiates a "translate" ChatComponent.

Parameters
string$key
array$withAn array of ChatComponent (or castable) to be used to fill in blanks in the message.
Returns
ChatComponent

◆ underline()

Phpcraft\ChatComponent::underline ( )

Sets $this->underlined to true.

Returns
ChatComponent $this

◆ white()

Phpcraft\ChatComponent::white ( )

Sets $this->color to "white".

Returns
ChatComponent $this

◆ yellow()

Phpcraft\ChatComponent::yellow ( )

Sets $this->color to "yellow".

Returns
ChatComponent $this

Member Data Documentation

◆ $attributes

array Phpcraft\ChatComponent::$attributes
static

◆ $attributes_ansi

array< string, string > Phpcraft\ChatComponent::$attributes_ansi
static

◆ $attributes_html

array< string, array > Phpcraft\ChatComponent::$attributes_html
static

◆ $attributes_legacy

array< string, string > Phpcraft\ChatComponent::$attributes_legacy
static

◆ $bold

bool Phpcraft\ChatComponent::$bold = false

◆ $click_event

array null Phpcraft\ChatComponent::$click_event = null

◆ $color

string null Phpcraft\ChatComponent::$color = null

◆ $color_to_ansi

array< string, string > Phpcraft\ChatComponent::$color_to_ansi
static

◆ $color_to_hex

array< string, string > Phpcraft\ChatComponent::$color_to_hex
static

◆ $color_to_rgb_hex

array< string, string > Phpcraft\ChatComponent::$color_to_rgb_hex
static

◆ $extra

Phpcraft\ChatComponent::$extra = []

◆ $hex_to_color

array< string, string > Phpcraft\ChatComponent::$hex_to_color
static

◆ $insertion

string null Phpcraft\ChatComponent::$insertion = null

Text to be inserted into the client's chat box when they shift-click the ChatComponent.

◆ $italic

bool Phpcraft\ChatComponent::$italic = false

◆ $keybind

string null Phpcraft\ChatComponent::$keybind = null
Since
0.4.1

◆ $obfuscated

bool Phpcraft\ChatComponent::$obfuscated = false

◆ $strikethrough

bool Phpcraft\ChatComponent::$strikethrough = false

◆ $text

string null Phpcraft\ChatComponent::$text

◆ $translate

string null Phpcraft\ChatComponent::$translate = null

◆ $translations

array< string, string > Phpcraft\ChatComponent::$translations
static

◆ $underlined

bool Phpcraft\ChatComponent::$underlined = false

◆ $with

Phpcraft\ChatComponent::$with = []

◆ FORMAT_AMPERSAND

const Phpcraft\ChatComponent::FORMAT_AMPERSAND = 3

&-format

◆ FORMAT_ANSI

const Phpcraft\ChatComponent::FORMAT_ANSI = 1

◆ FORMAT_HTML

const Phpcraft\ChatComponent::FORMAT_HTML = 4

◆ FORMAT_NONE

const Phpcraft\ChatComponent::FORMAT_NONE = 0

◆ FORMAT_SILCROW

const Phpcraft\ChatComponent::FORMAT_SILCROW = 2

§-format