diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index 5329968df..fbdf19f88 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -80,6 +80,18 @@ abstract class TextFormat{ return str_replace("\x1b", "", preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string)); } + /** + * Replaces placeholders of ยง with the correct character. Only valid codes (as in the constants of the TextFormat class) will be converted. + * + * @param string $string + * @param string $placeholder default "&" + * + * @return string + */ + public static function colorize(string $string, string $placeholder = "&") : string{ + return preg_replace('/' . preg_quote($placeholder, "/") . '([0-9a-fk-or])/u', TextFormat::ESCAPE . '$1', $string); + } + /** * Returns an JSON-formatted string with colors/markup *