Skip to content

Instantly share code, notes, and snippets.

@DragonHunt3r
DragonHunt3r / ColorOptimizer.java
Last active April 22, 2019 11:24
Minecraft ChatColor optimizer
public class ColorOptimizer {
/**
* Matches text until next color code.
* &a&lSome&b&oText -> &a&lSome, &b&oText
*/
private static final Pattern SPLIT_PATTERN = Pattern.compile("(" + ChatColor.COLOR_CHAR + "[0-9A-Fa-fK-Ok-oRr])+(.*?)(?=(?:" + ChatColor.COLOR_CHAR + "[0-9A-Fa-fK-Ok-oRr])|$)");
/**
* Matches any color.
*/
private static final Pattern COLOR = Pattern.compile("(" + ChatColor.COLOR_CHAR + "[0-9A-Fa-f])");