PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
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 javaToBedrock (string $string)
 
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 MATERIAL_AMETHYST = TextFormat::ESCAPE . "u"
 
const MATERIAL_COPPER = TextFormat::ESCAPE . "n"
 
const MATERIAL_DIAMOND = TextFormat::ESCAPE . "s"
 
const MATERIAL_EMERALD = TextFormat::ESCAPE . "q"
 
const MATERIAL_GOLD = TextFormat::ESCAPE . "p"
 
const MATERIAL_IRON = TextFormat::ESCAPE . "i"
 
const MATERIAL_LAPIS = TextFormat::ESCAPE . "t"
 
const MATERIAL_NETHERITE = TextFormat::ESCAPE . "j"
 
const MATERIAL_QUARTZ = TextFormat::ESCAPE . "h"
 
const MATERIAL_REDSTONE = TextFormat::ESCAPE . "m"
 
const MINECOIN_GOLD = TextFormat::ESCAPE . "g"
 
const OBFUSCATED = TextFormat::ESCAPE . "k"
 
const RED = TextFormat::ESCAPE . "c"
 
const RESET = TextFormat::ESCAPE . "r"
 
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 190 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 159 of file TextFormat.php.

◆ 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 173 of file TextFormat.php.

◆ javaToBedrock()

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

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.

Definition at line 212 of file TextFormat.php.

◆ toHTML()

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

Returns an HTML-formatted string with colors/markup

Definition at line 219 of file TextFormat.php.

◆ tokenize()

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

Splits the string by Format tokens

Returns
string[]

Definition at line 148 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 108 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,
self::MATERIAL_QUARTZ => self::MATERIAL_QUARTZ,
self::MATERIAL_IRON => self::MATERIAL_IRON,
self::MATERIAL_NETHERITE => self::MATERIAL_NETHERITE,
self::MATERIAL_REDSTONE => self::MATERIAL_REDSTONE,
self::MATERIAL_COPPER => self::MATERIAL_COPPER,
self::MATERIAL_GOLD => self::MATERIAL_GOLD,
self::MATERIAL_EMERALD => self::MATERIAL_EMERALD,
self::MATERIAL_DIAMOND => self::MATERIAL_DIAMOND,
self::MATERIAL_LAPIS => self::MATERIAL_LAPIS,
self::MATERIAL_AMETHYST => self::MATERIAL_AMETHYST,
]

Definition at line 77 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::ITALIC => self::ITALIC,
]

Definition at line 111 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 109 of file TextFormat.php.

◆ LIGHT_PURPLE

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

Definition at line 62 of file TextFormat.php.

◆ MATERIAL_AMETHYST

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

Definition at line 75 of file TextFormat.php.

◆ MATERIAL_COPPER

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

Definition at line 70 of file TextFormat.php.

◆ MATERIAL_DIAMOND

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

Definition at line 73 of file TextFormat.php.

◆ MATERIAL_EMERALD

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

Definition at line 72 of file TextFormat.php.

◆ MATERIAL_GOLD

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

Definition at line 71 of file TextFormat.php.

◆ MATERIAL_IRON

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

Definition at line 67 of file TextFormat.php.

◆ MATERIAL_LAPIS

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

Definition at line 74 of file TextFormat.php.

◆ MATERIAL_NETHERITE

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

Definition at line 68 of file TextFormat.php.

◆ MATERIAL_QUARTZ

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

Definition at line 66 of file TextFormat.php.

◆ MATERIAL_REDSTONE

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

Definition at line 69 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 107 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 117 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: