diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index d790e8c10..9bc9dcdde 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -83,6 +83,18 @@ public static function clean($string, $removeFormat = true){ 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 * @@ -582,4 +594,4 @@ public static function addSpaces($string, $resPixelLength, $mode = self::MODE_BO return $string; } -} \ No newline at end of file +}