Skip to content

TextFormat ​

abstract class · pocketmine\utils\TextFormat · source

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

Constants ​

AQUA ​

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

BLACK ​

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

BLUE ​

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

BOLD ​

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

COLORS ​

php
public const 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::AQU …

DARK_AQUA ​

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

DARK_BLUE ​

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

DARK_GRAY ​

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

DARK_GREEN ​

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

DARK_PURPLE ​

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

DARK_RED ​

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

EOL ​

php
public const EOL = "\n"

ESCAPE ​

php
public const ESCAPE = "§"

FORMATS ​

php
public const FORMATS = [self::OBFUSCATED => self::OBFUSCATED, self::BOLD => self::BOLD, self::ITALIC => self::ITALIC]

GOLD ​

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

GRAY ​

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

GREEN ​

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

ITALIC ​

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

LIGHT_PURPLE ​

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

MATERIAL_AMETHYST ​

php
public const MATERIAL_AMETHYST = \pocketmine\utils\TextFormat::ESCAPE . "u"

MATERIAL_COPPER ​

php
public const MATERIAL_COPPER = \pocketmine\utils\TextFormat::ESCAPE . "n"

MATERIAL_DIAMOND ​

php
public const MATERIAL_DIAMOND = \pocketmine\utils\TextFormat::ESCAPE . "s"

MATERIAL_EMERALD ​

php
public const MATERIAL_EMERALD = \pocketmine\utils\TextFormat::ESCAPE . "q"

MATERIAL_GOLD ​

php
public const MATERIAL_GOLD = \pocketmine\utils\TextFormat::ESCAPE . "p"

MATERIAL_IRON ​

php
public const MATERIAL_IRON = \pocketmine\utils\TextFormat::ESCAPE . "i"

MATERIAL_LAPIS ​

php
public const MATERIAL_LAPIS = \pocketmine\utils\TextFormat::ESCAPE . "t"

MATERIAL_NETHERITE ​

php
public const MATERIAL_NETHERITE = \pocketmine\utils\TextFormat::ESCAPE . "j"

MATERIAL_QUARTZ ​

php
public const MATERIAL_QUARTZ = \pocketmine\utils\TextFormat::ESCAPE . "h"

MATERIAL_REDSTONE ​

php
public const MATERIAL_REDSTONE = \pocketmine\utils\TextFormat::ESCAPE . "m"

MATERIAL_RESIN ​

php
public const MATERIAL_RESIN = \pocketmine\utils\TextFormat::ESCAPE . "v"

MINECOIN_GOLD ​

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

OBFUSCATED ​

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

RED ​

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

RESET ​

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

STRIKETHROUGH ​

php
public const STRIKETHROUGH = ""

Deprecated

Deprecated.

UNDERLINE ​

php
public const UNDERLINE = ""

Deprecated

Deprecated.

WHITE ​

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

YELLOW ​

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

Methods ​

addBase() ​

php
public static function addBase(string $baseFormat, string $string) : string

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.

clean() ​

php
public static function clean(string $string, bool $removeFormat = true) : string

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

colorize() ​

php
public static function colorize(string $string, string $placeholder = "&") : string

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

javaToBedrock() ​

php
public static function javaToBedrock(string $string) : string

Converts any Java formatting codes in the given string to Bedrock.

As of 1.21.50, strikethrough (§m) and underline (§n) are not supported by Bedrock, and these symbols are instead used to represent additional colours in Bedrock. To avoid unintended formatting, this function currently strips those formatting codes to prevent unintended colour display in formatted text.

If Bedrock starts to support these formats in the future, this function will be updated to translate them rather than removing them.

toHTML() ​

php
public static function toHTML(string $string) : string

Returns an HTML-formatted string with colors/markup

tokenize() ​

php
public static function tokenize(string $string) : array

Splits the string by Format tokens

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.