PocketMine-MP 5.14.2 git-50e2c469a547a16a23b2dc691e70a51d34e29395
pocketmine\utils\TextFormat Class Reference
+ Collaboration diagram for pocketmine\utils\TextFormat:

Static Public Member Functions

static addBase (string $baseFormat, string $string)
 
static clean (string $string, bool $removeFormat=true)
 
static colorize (string $string, string $placeholder="&")
 
static toHTML (string $string)
 
static tokenize (string $string)
 

Public Attributes

const AQUA = TextFormat::ESCAPE . "b"
 
const BLACK = TextFormat::ESCAPE . "0"
 
const BLUE = TextFormat::ESCAPE . "9"
 
const BOLD = TextFormat::ESCAPE . "l"
 
const COLORS
 
const DARK_AQUA = TextFormat::ESCAPE . "3"
 
const DARK_BLUE = TextFormat::ESCAPE . "1"
 
const DARK_GRAY = TextFormat::ESCAPE . "8"
 
const DARK_GREEN = TextFormat::ESCAPE . "2"
 
const DARK_PURPLE = TextFormat::ESCAPE . "5"
 
const DARK_RED = TextFormat::ESCAPE . "4"
 
const EOL = "\n"
 
const ESCAPE = "\xc2\xa7"
 
const FORMATS
 
const GOLD = TextFormat::ESCAPE . "6"
 
const GRAY = TextFormat::ESCAPE . "7"
 
const GREEN = TextFormat::ESCAPE . "a"
 
const ITALIC = TextFormat::ESCAPE . "o"
 
const LIGHT_PURPLE = TextFormat::ESCAPE . "d"
 
const MINECOIN_GOLD = TextFormat::ESCAPE . "g"
 
const OBFUSCATED = TextFormat::ESCAPE . "k"
 
const RED = TextFormat::ESCAPE . "c"
 
const RESET = TextFormat::ESCAPE . "r"
 
const STRIKETHROUGH = TextFormat::ESCAPE . "m"
 
const UNDERLINE = TextFormat::ESCAPE . "n"
 
const WHITE = TextFormat::ESCAPE . "f"
 
const YELLOW = TextFormat::ESCAPE . "e"
 

Detailed Description

Class used to handle Minecraft chat format, and convert it to other formats like HTML

Definition at line 45 of file TextFormat.php.

Member Function Documentation

◆ addBase()

static pocketmine\utils\TextFormat::addBase ( string  $baseFormat,
string  $string 
)
static

Adds base formatting to the string. The given format codes will be inserted directly after any RESET (§r) codes.

This is useful for log messages, where a RESET code should return to the log message's original colour (e.g. blue for NOTICE), rather than whatever the terminal's base text colour is (usually some off-white colour).

Example behaviour:

  • Base format "§c" (red) + "Hello" (no format) = "§r§cHello"
  • Base format "§c" + "Hello §rWorld" = "§r§cHello §r§cWorld"

Note: Adding base formatting to the output string a second time will result in a combination of formats from both calls. This is not by design, but simply a consequence of the way the function is implemented.

Definition at line 174 of file TextFormat.php.

◆ clean()

static pocketmine\utils\TextFormat::clean ( string  $string,
bool  $removeFormat = true 
)
static

Cleans the string from Minecraft codes, ANSI Escape Codes and invalid UTF-8 characters

Returns
string valid clean UTF-8

Definition at line 143 of file TextFormat.php.

Referenced by pocketmine\player\PlayerInfo\__construct().

+ Here is the caller graph for this function:

◆ colorize()

static pocketmine\utils\TextFormat::colorize ( string  $string,
string  $placeholder = "&" 
)
static

Replaces placeholders of § with the correct character. Only valid codes (as in the constants of the TextFormat class) will be converted.

Parameters
string$placeholderdefault "&"

Definition at line 157 of file TextFormat.php.

◆ toHTML()

static pocketmine\utils\TextFormat::toHTML ( string  $string)
static

Returns an HTML-formatted string with colors/markup

Definition at line 189 of file TextFormat.php.

◆ tokenize()

static pocketmine\utils\TextFormat::tokenize ( string  $string)
static

Splits the string by Format tokens

Returns
string[]

Definition at line 132 of file TextFormat.php.

Member Data Documentation

◆ AQUA

const pocketmine\utils\TextFormat::AQUA = TextFormat::ESCAPE . "b"

Definition at line 60 of file TextFormat.php.

◆ BLACK

const pocketmine\utils\TextFormat::BLACK = TextFormat::ESCAPE . "0"

Definition at line 49 of file TextFormat.php.

◆ BLUE

const pocketmine\utils\TextFormat::BLUE = TextFormat::ESCAPE . "9"

Definition at line 58 of file TextFormat.php.

◆ BOLD

const pocketmine\utils\TextFormat::BOLD = TextFormat::ESCAPE . "l"

Definition at line 88 of file TextFormat.php.

◆ COLORS

const pocketmine\utils\TextFormat::COLORS
Initial value:
= [
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,
self::MINECOIN_GOLD => self::MINECOIN_GOLD,
]

Definition at line 67 of file TextFormat.php.

◆ DARK_AQUA

const pocketmine\utils\TextFormat::DARK_AQUA = TextFormat::ESCAPE . "3"

Definition at line 52 of file TextFormat.php.

◆ DARK_BLUE

const pocketmine\utils\TextFormat::DARK_BLUE = TextFormat::ESCAPE . "1"

Definition at line 50 of file TextFormat.php.

◆ DARK_GRAY

const pocketmine\utils\TextFormat::DARK_GRAY = TextFormat::ESCAPE . "8"

Definition at line 57 of file TextFormat.php.

◆ DARK_GREEN

const pocketmine\utils\TextFormat::DARK_GREEN = TextFormat::ESCAPE . "2"

Definition at line 51 of file TextFormat.php.

◆ DARK_PURPLE

const pocketmine\utils\TextFormat::DARK_PURPLE = TextFormat::ESCAPE . "5"

Definition at line 54 of file TextFormat.php.

◆ DARK_RED

const pocketmine\utils\TextFormat::DARK_RED = TextFormat::ESCAPE . "4"

Definition at line 53 of file TextFormat.php.

◆ EOL

const pocketmine\utils\TextFormat::EOL = "\n"

Definition at line 47 of file TextFormat.php.

◆ ESCAPE

const pocketmine\utils\TextFormat::ESCAPE = "\xc2\xa7"

Definition at line 46 of file TextFormat.php.

◆ FORMATS

const pocketmine\utils\TextFormat::FORMATS
Initial value:
= [
self::OBFUSCATED => self::OBFUSCATED,
self::BOLD => self::BOLD,
self::STRIKETHROUGH => self::STRIKETHROUGH,
self::UNDERLINE => self::UNDERLINE,
self::ITALIC => self::ITALIC,
]

Definition at line 93 of file TextFormat.php.

◆ GOLD

const pocketmine\utils\TextFormat::GOLD = TextFormat::ESCAPE . "6"

Definition at line 55 of file TextFormat.php.

◆ GRAY

const pocketmine\utils\TextFormat::GRAY = TextFormat::ESCAPE . "7"

Definition at line 56 of file TextFormat.php.

◆ GREEN

const pocketmine\utils\TextFormat::GREEN = TextFormat::ESCAPE . "a"

Definition at line 59 of file TextFormat.php.

◆ ITALIC

const pocketmine\utils\TextFormat::ITALIC = TextFormat::ESCAPE . "o"

Definition at line 91 of file TextFormat.php.

◆ LIGHT_PURPLE

const pocketmine\utils\TextFormat::LIGHT_PURPLE = TextFormat::ESCAPE . "d"

Definition at line 62 of file TextFormat.php.

◆ MINECOIN_GOLD

const pocketmine\utils\TextFormat::MINECOIN_GOLD = TextFormat::ESCAPE . "g"

Definition at line 65 of file TextFormat.php.

◆ OBFUSCATED

const pocketmine\utils\TextFormat::OBFUSCATED = TextFormat::ESCAPE . "k"

Definition at line 87 of file TextFormat.php.

◆ RED

const pocketmine\utils\TextFormat::RED = TextFormat::ESCAPE . "c"

Definition at line 61 of file TextFormat.php.

◆ RESET

const pocketmine\utils\TextFormat::RESET = TextFormat::ESCAPE . "r"

Definition at line 101 of file TextFormat.php.

◆ STRIKETHROUGH

const pocketmine\utils\TextFormat::STRIKETHROUGH = TextFormat::ESCAPE . "m"

Definition at line 89 of file TextFormat.php.

◆ UNDERLINE

const pocketmine\utils\TextFormat::UNDERLINE = TextFormat::ESCAPE . "n"

Definition at line 90 of file TextFormat.php.

◆ WHITE

const pocketmine\utils\TextFormat::WHITE = TextFormat::ESCAPE . "f"

Definition at line 64 of file TextFormat.php.

◆ YELLOW

const pocketmine\utils\TextFormat::YELLOW = TextFormat::ESCAPE . "e"

Definition at line 63 of file TextFormat.php.


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