TextFormat
in package
Class used to handle Minecraft chat format, and convert it to other formats like HTML
Table of Contents
- AQUA = \pocketmine\utils\TextFormat::ESCAPE . "b"
- BLACK = \pocketmine\utils\TextFormat::ESCAPE . "0"
- BLUE = \pocketmine\utils\TextFormat::ESCAPE . "9"
- BOLD = \pocketmine\utils\TextFormat::ESCAPE . "l"
- COLORS = [self::BLACK => self::BLACK, self::DARK_BLUE => self::DARK_BLUE, self::DARK_GREEN => self::DARK_GREEN, self::DARK_AQUA => self::DARK_AQUA, self::DARK_RED => self::DARK_RED, self::DARK_PURPLE => self::DARK_PURPLE, self::GOLD => self::GOLD, self::GRAY => self::GRAY, self::DARK_GRAY => self::DARK_GRAY, self::BLUE => self::BLUE, self::GREEN => self::GREEN, self::AQUA => self::AQUA, self::RED => self::RED, self::LIGHT_PURPLE => self::LIGHT_PURPLE, self::YELLOW => self::YELLOW, self::WHITE => self::WHITE]
- DARK_AQUA = \pocketmine\utils\TextFormat::ESCAPE . "3"
- DARK_BLUE = \pocketmine\utils\TextFormat::ESCAPE . "1"
- DARK_GRAY = \pocketmine\utils\TextFormat::ESCAPE . "8"
- DARK_GREEN = \pocketmine\utils\TextFormat::ESCAPE . "2"
- DARK_PURPLE = \pocketmine\utils\TextFormat::ESCAPE . "5"
- DARK_RED = \pocketmine\utils\TextFormat::ESCAPE . "4"
- EOL = "\n"
- ESCAPE = "§"
- FORMATS = [self::OBFUSCATED => self::OBFUSCATED, self::BOLD => self::BOLD, self::STRIKETHROUGH => self::STRIKETHROUGH, self::UNDERLINE => self::UNDERLINE, self::ITALIC => self::ITALIC]
- GOLD = \pocketmine\utils\TextFormat::ESCAPE . "6"
- GRAY = \pocketmine\utils\TextFormat::ESCAPE . "7"
- GREEN = \pocketmine\utils\TextFormat::ESCAPE . "a"
- ITALIC = \pocketmine\utils\TextFormat::ESCAPE . "o"
- LIGHT_PURPLE = \pocketmine\utils\TextFormat::ESCAPE . "d"
- OBFUSCATED = \pocketmine\utils\TextFormat::ESCAPE . "k"
- RED = \pocketmine\utils\TextFormat::ESCAPE . "c"
- RESET = \pocketmine\utils\TextFormat::ESCAPE . "r"
- STRIKETHROUGH = \pocketmine\utils\TextFormat::ESCAPE . "m"
- UNDERLINE = \pocketmine\utils\TextFormat::ESCAPE . "n"
- WHITE = \pocketmine\utils\TextFormat::ESCAPE . "f"
- YELLOW = \pocketmine\utils\TextFormat::ESCAPE . "e"
- clean() : string
- Cleans the string from Minecraft codes, ANSI Escape Codes and invalid UTF-8 characters
- colorize() : string
- Replaces placeholders of § with the correct character. Only valid codes (as in the constants of the TextFormat class) will be converted.
- toHTML() : string
- Returns an HTML-formatted string with colors/markup
- tokenize() : array<string|int, string>
- Splits the string by Format tokens
- makePcreError() : InvalidArgumentException
- preg_replace() : string
Constants
AQUA
public
mixed
AQUA
= \pocketmine\utils\TextFormat::ESCAPE . "b"
BLACK
public
mixed
BLACK
= \pocketmine\utils\TextFormat::ESCAPE . "0"
BLUE
public
mixed
BLUE
= \pocketmine\utils\TextFormat::ESCAPE . "9"
BOLD
public
mixed
BOLD
= \pocketmine\utils\TextFormat::ESCAPE . "l"
COLORS
public
mixed
COLORS
= [self::BLACK => self::BLACK, self::DARK_BLUE => self::DARK_BLUE, self::DARK_GREEN => self::DARK_GREEN, self::DARK_AQUA => self::DARK_AQUA, self::DARK_RED => self::DARK_RED, self::DARK_PURPLE => self::DARK_PURPLE, self::GOLD => self::GOLD, self::GRAY => self::GRAY, self::DARK_GRAY => self::DARK_GRAY, self::BLUE => self::BLUE, self::GREEN => self::GREEN, self::AQUA => self::AQUA, self::RED => self::RED, self::LIGHT_PURPLE => self::LIGHT_PURPLE, self::YELLOW => self::YELLOW, self::WHITE => self::WHITE]
DARK_AQUA
public
mixed
DARK_AQUA
= \pocketmine\utils\TextFormat::ESCAPE . "3"
DARK_BLUE
public
mixed
DARK_BLUE
= \pocketmine\utils\TextFormat::ESCAPE . "1"
DARK_GRAY
public
mixed
DARK_GRAY
= \pocketmine\utils\TextFormat::ESCAPE . "8"
DARK_GREEN
public
mixed
DARK_GREEN
= \pocketmine\utils\TextFormat::ESCAPE . "2"
DARK_PURPLE
public
mixed
DARK_PURPLE
= \pocketmine\utils\TextFormat::ESCAPE . "5"
DARK_RED
public
mixed
DARK_RED
= \pocketmine\utils\TextFormat::ESCAPE . "4"
EOL
public
mixed
EOL
= "\n"
ESCAPE
public
mixed
ESCAPE
= "§"
FORMATS
public
mixed
FORMATS
= [self::OBFUSCATED => self::OBFUSCATED, self::BOLD => self::BOLD, self::STRIKETHROUGH => self::STRIKETHROUGH, self::UNDERLINE => self::UNDERLINE, self::ITALIC => self::ITALIC]
GOLD
public
mixed
GOLD
= \pocketmine\utils\TextFormat::ESCAPE . "6"
GRAY
public
mixed
GRAY
= \pocketmine\utils\TextFormat::ESCAPE . "7"
GREEN
public
mixed
GREEN
= \pocketmine\utils\TextFormat::ESCAPE . "a"
ITALIC
public
mixed
ITALIC
= \pocketmine\utils\TextFormat::ESCAPE . "o"
LIGHT_PURPLE
public
mixed
LIGHT_PURPLE
= \pocketmine\utils\TextFormat::ESCAPE . "d"
OBFUSCATED
public
mixed
OBFUSCATED
= \pocketmine\utils\TextFormat::ESCAPE . "k"
RED
public
mixed
RED
= \pocketmine\utils\TextFormat::ESCAPE . "c"
RESET
public
mixed
RESET
= \pocketmine\utils\TextFormat::ESCAPE . "r"
STRIKETHROUGH
public
mixed
STRIKETHROUGH
= \pocketmine\utils\TextFormat::ESCAPE . "m"
UNDERLINE
public
mixed
UNDERLINE
= \pocketmine\utils\TextFormat::ESCAPE . "n"
WHITE
public
mixed
WHITE
= \pocketmine\utils\TextFormat::ESCAPE . "f"
YELLOW
public
mixed
YELLOW
= \pocketmine\utils\TextFormat::ESCAPE . "e"
Methods
clean()
Cleans the string from Minecraft codes, ANSI Escape Codes and invalid UTF-8 characters
public
static clean(string $string[, bool $removeFormat = true ]) : string
Parameters
- $string : string
- $removeFormat : bool = true
Return values
string —valid clean UTF-8
colorize()
Replaces placeholders of § with the correct character. Only valid codes (as in the constants of the TextFormat class) will be converted.
public
static colorize(string $string[, string $placeholder = "&" ]) : string
Parameters
- $string : string
- $placeholder : string = "&"
-
default "&"
Return values
string —toHTML()
Returns an HTML-formatted string with colors/markup
public
static toHTML(string $string) : string
Parameters
- $string : string
Return values
string —tokenize()
Splits the string by Format tokens
public
static tokenize(string $string) : array<string|int, string>
Parameters
- $string : string
Return values
array<string|int, string> —makePcreError()
private
static makePcreError() : InvalidArgumentException
Return values
InvalidArgumentException —preg_replace()
private
static preg_replace(string $pattern, string $replacement, string $string) : string
Parameters
- $pattern : string
- $replacement : string
- $string : string